diff options
author | William Pitcock <nenolod@dereferenced.org> | 2018-06-18 04:33:41 +0000 |
---|---|---|
committer | William Pitcock <nenolod@dereferenced.org> | 2018-06-18 04:36:25 +0000 |
commit | 591c82620eeb74a012d4614b9f16db74a7fd84f9 (patch) | |
tree | 04b66e0ba384ceec5a2b130b193a919ac23f755a /lib | |
parent | 25946f772d1c1d3ff8a4d2c70824654a9c22fc23 (diff) | |
download | pleroma-591c82620eeb74a012d4614b9f16db74a7fd84f9.tar.gz |
activitypub: filter destination list for announce activities differently than normal (closes #164)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/user.ex | 28 | ||||
-rw-r--r-- | lib/pleroma/web/activity_pub/activity_pub.ex | 18 |
2 files changed, 40 insertions, 6 deletions
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index b27397e13..856f27e10 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -449,13 +449,29 @@ defmodule Pleroma.User do update_and_set_cache(cs) end + def get_notified_from_activity_query(to) do + from( + u in User, + where: u.ap_id in ^to, + where: u.local == true + ) + end + + def get_notified_from_activity(%Activity{recipients: to, data: %{"type" => "Announce"} = data}) do + object = Object.get_by_ap_id(data["object"]) + + # ensure that the actor who published the announced object appears only once + to = + (to ++ [object.data["actor"]]) + |> Enum.uniq() + + query = get_notified_from_activity_query(to) + + Repo.all(query) + end + def get_notified_from_activity(%Activity{recipients: to}) do - query = - from( - u in User, - where: u.ap_id in ^to, - where: u.local == true - ) + query = get_notified_from_activity_query(to) Repo.all(query) end diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex index 267427a23..a4b49e73c 100644 --- a/lib/pleroma/web/activity_pub/activity_pub.ex +++ b/lib/pleroma/web/activity_pub/activity_pub.ex @@ -12,6 +12,24 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do @instance Application.get_env(:pleroma, :instance) + # For Announce activities, we filter the recipients based on following status for any actors + # that match actual users. See issue #164 for more information about why this is necessary. + def get_recipients(%{"type" => "Announce"} = data) do + recipients = (data["to"] || []) ++ (data["cc"] || []) + actor = User.get_cached_by_ap_id(data["actor"]) + + recipients + |> Enum.filter(fn recipient -> + case User.get_cached_by_ap_id(recipient) do + nil -> + true + + user -> + User.following?(user, actor) + end + end) + end + def get_recipients(data) do (data["to"] || []) ++ (data["cc"] || []) end |