aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/web/twitter_api
diff options
context:
space:
mode:
authorIvan Tashkinov <ivantashkinov@gmail.com>2019-02-19 19:10:55 +0300
committerIvan Tashkinov <ivantashkinov@gmail.com>2019-02-19 19:10:55 +0300
commitc0ecbf6669948740a091bdf5b5441fb6ee55f4fc (patch)
tree9ad9fadc6855b1529df7ce8403683c32f776265b /lib/pleroma/web/twitter_api
parentd3fe2c8ec6116fbc3058f7a795ef59564bddfb08 (diff)
parent1dd718e83c76db218f12a98344b568fe10ecbefe (diff)
downloadpleroma-c0ecbf6669948740a091bdf5b5441fb6ee55f4fc.tar.gz
[#468] Merged `upstream/develop`.
Diffstat (limited to 'lib/pleroma/web/twitter_api')
-rw-r--r--lib/pleroma/web/twitter_api/twitter_api_controller.ex25
-rw-r--r--lib/pleroma/web/twitter_api/views/token_view.ex21
-rw-r--r--lib/pleroma/web/twitter_api/views/user_view.ex18
3 files changed, 58 insertions, 6 deletions
diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex
index c2f0dc2a9..b815379fd 100644
--- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex
+++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex
@@ -8,6 +8,10 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
import Pleroma.Web.ControllerHelper, only: [json_response: 3]
alias Ecto.Changeset
+ alias Pleroma.Web.TwitterAPI.{TwitterAPI, UserView, ActivityView, NotificationView, TokenView}
+ alias Pleroma.Web.CommonAPI
+ alias Pleroma.{Repo, Activity, Object, User, Notification}
+ alias Pleroma.Web.OAuth.Token
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.CommonAPI
@@ -524,6 +528,9 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
def friends(%{assigns: %{user: for_user}} = conn, params) do
{:ok, page} = Ecto.Type.cast(:integer, params["page"] || 1)
+ {:ok, export} = Ecto.Type.cast(:boolean, params["all"] || false)
+
+ page = if export, do: nil, else: page
with {:ok, user} <- TwitterAPI.get_user(conn.assigns[:user], params),
{:ok, friends} <- User.get_friends(user, page) do
@@ -542,6 +549,20 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
end
end
+ def oauth_tokens(%{assigns: %{user: user}} = conn, _params) do
+ with oauth_tokens <- Token.get_user_tokens(user) do
+ conn
+ |> put_view(TokenView)
+ |> render("index.json", %{tokens: oauth_tokens})
+ end
+ end
+
+ def revoke_token(%{assigns: %{user: user}} = conn, %{"id" => id} = _params) do
+ Token.delete_user_token(user, id)
+
+ json_reply(conn, 201, "")
+ end
+
def blocks(%{assigns: %{user: user}} = conn, _params) do
with blocked_users <- User.blocked_users(user) do
conn
@@ -570,7 +591,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
{:ok, _activity} <-
ActivityPub.accept(%{
to: [follower.ap_id],
- actor: followed.ap_id,
+ actor: followed,
object: follow_activity.data["id"],
type: "Accept"
}) do
@@ -590,7 +611,7 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
{:ok, _activity} <-
ActivityPub.reject(%{
to: [follower.ap_id],
- actor: followed.ap_id,
+ actor: followed,
object: follow_activity.data["id"],
type: "Reject"
}) do
diff --git a/lib/pleroma/web/twitter_api/views/token_view.ex b/lib/pleroma/web/twitter_api/views/token_view.ex
new file mode 100644
index 000000000..3ff314913
--- /dev/null
+++ b/lib/pleroma/web/twitter_api/views/token_view.ex
@@ -0,0 +1,21 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.TwitterAPI.TokenView do
+ use Pleroma.Web, :view
+
+ def render("index.json", %{tokens: tokens}) do
+ tokens
+ |> render_many(Pleroma.Web.TwitterAPI.TokenView, "show.json")
+ |> Enum.filter(&Enum.any?/1)
+ end
+
+ def render("show.json", %{token: token_entry}) do
+ %{
+ id: token_entry.id,
+ valid_until: token_entry.valid_until,
+ app_name: token_entry.app.client_name
+ }
+ end
+end
diff --git a/lib/pleroma/web/twitter_api/views/user_view.ex b/lib/pleroma/web/twitter_api/views/user_view.ex
index a09450df7..df7384476 100644
--- a/lib/pleroma/web/twitter_api/views/user_view.ex
+++ b/lib/pleroma/web/twitter_api/views/user_view.ex
@@ -113,10 +113,12 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
"fields" => fields,
# Pleroma extension
- "pleroma" => %{
- "confirmation_pending" => user_info.confirmation_pending,
- "tags" => user.tags
- }
+ "pleroma" =>
+ %{
+ "confirmation_pending" => user_info.confirmation_pending,
+ "tags" => user.tags
+ }
+ |> maybe_with_follow_request_count(user, for_user)
}
data =
@@ -132,6 +134,14 @@ defmodule Pleroma.Web.TwitterAPI.UserView do
end
end
+ defp maybe_with_follow_request_count(data, %User{id: id, info: %{locked: true}} = user, %User{
+ id: id
+ }) do
+ Map.put(data, "follow_request_count", user.info.follow_request_count)
+ end
+
+ defp maybe_with_follow_request_count(data, _, _), do: data
+
defp maybe_with_role(data, %User{id: id} = user, %User{id: id}) do
Map.merge(data, %{"role" => role(user), "show_role" => user.info.show_role})
end