summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Pitcock <nenolod@dereferenced.org>2018-05-26 16:16:20 +0000
committerWilliam Pitcock <nenolod@dereferenced.org>2018-06-11 22:15:53 +0000
commit6f89d2d583c76d9a2c9908f560902bc75609c8ab (patch)
treef90d60da51a25b77572c031ac4a56265f39a0c4a
parent9c889334220487c4e370333a13908639b984bc19 (diff)
downloadpleroma-6f89d2d583c76d9a2c9908f560902bc75609c8ab.tar.gz
pleroma-6f89d2d583c76d9a2c9908f560902bc75609c8ab.zip
stash api controller
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api_controller.ex24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index e92c6277b..90b0da8da 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -4,6 +4,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
alias Pleroma.Web
alias Pleroma.Web.MastodonAPI.{StatusView, AccountView, MastodonView, ListView}
alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.{CommonAPI, OStatus}
alias Pleroma.Web.OAuth.{Authorization, Token, App}
alias Comeonin.Pbkdf2
@@ -482,6 +483,29 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
end
+ def authorize_follow_request(%{assigns: %{user: followed}} = conn, %{"id" => id}) do
+ with %User{} = follower <- Repo.get(User, id),
+ {:ok, follower} <- User.follow(follower, followed),
+ %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed),
+ {:ok, _activity} <-
+ ActivityPub.accept(%{
+ to: follower.ap_id,
+ actor: followed.ap_id,
+ object: follow_activity.data["id"],
+ type: "Accept"
+ }) do
+ render(conn, AccountView, "relationship.json", %{user: followed, target: follower})
+ else
+ {:error, message} ->
+ conn
+ |> put_resp_content_type("application/json")
+ |> send_resp(403, Jason.encode!(%{"error" => message}))
+ end
+ end
+
+ # def reject_follow_request(%{assigns: %{user: followed}} = conn, %{"id" => id}) do
+ # end
+
def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
with %User{} = followed <- Repo.get(User, id),
{:ok, follower} <- User.maybe_direct_follow(follower, followed),