From cbb2b709de72c72542b0db883fa7b1b7d886688b Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 29 Jan 2019 11:57:46 +0000 Subject: [PATCH 1/2] activitypub: transmogrifier: fix follow request rejections --- lib/pleroma/web/activity_pub/transmogrifier.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index c2ced51d8..43725c3db 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -453,9 +453,9 @@ def handle_incoming( {:ok, follow_activity} <- Utils.update_follow_state(follow_activity, "reject"), %User{local: true} = follower <- User.get_cached_by_ap_id(follow_activity.data["actor"]), {:ok, activity} <- - ActivityPub.accept(%{ + ActivityPub.reject(%{ to: follow_activity.data["to"], - type: "Accept", + type: "Reject", actor: followed.ap_id, object: follow_activity.data["id"], local: false From 57549f60434250d538d61b926906c0b7d284c627 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 29 Jan 2019 12:21:02 +0000 Subject: [PATCH 2/2] activitypub: utils: update the state of *any* pending follow relationship that matches the actor and target --- lib/pleroma/web/activity_pub/utils.ex | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/pleroma/web/activity_pub/utils.ex b/lib/pleroma/web/activity_pub/utils.ex index e40d05fcd..3b0cdfe71 100644 --- a/lib/pleroma/web/activity_pub/utils.ex +++ b/lib/pleroma/web/activity_pub/utils.ex @@ -316,6 +316,25 @@ def remove_like_from_object(%Activity{data: %{"actor" => actor}}, object) do @doc """ Updates a follow activity's state (for locked accounts). """ + def update_follow_state( + %Activity{data: %{"actor" => actor, "object" => object, "state" => "pending"}} = activity, + state + ) do + try do + Ecto.Adapters.SQL.query!( + Repo, + "UPDATE activities SET data = jsonb_set(data, '{state}', $1) WHERE data->>'type' = 'Follow' AND data->>'actor' = $2 AND data->>'object' = $3 AND data->>'state' = 'pending'", + [state, actor, object] + ) + + activity = Repo.get(Activity, activity.id) + {:ok, activity} + rescue + e -> + {:error, e} + end + end + def update_follow_state(%Activity{} = activity, state) do with new_data <- activity.data