logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma
commit: 440b459cd14778e155cd6a3550847b1277fbd1f1
parent: 63094cfd3ec0a9ca6e17a3ba6fa8271050cfb9b0
Author: lambda <pleromagit@rogerbraun.net>
Date:   Mon, 27 Aug 2018 08:25:27 +0000

Merge branch 'bugfix/announce-timeline-flooding' into 'develop'

activitypub: filter destination list for announce activities differently than normal (closes #164)

Closes #164

See merge request pleroma/pleroma!227

Diffstat:

Mlib/pleroma/user.ex28++++++++++++++++++++++------
Mlib/pleroma/web/activity_pub/activity_pub.ex18++++++++++++++++++
Mlib/pleroma/web/ostatus/activity_representer.ex5++++-
3 files changed, 44 insertions(+), 7 deletions(-)

diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex @@ -457,13 +457,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.normalize(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 @@ -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 diff --git a/lib/pleroma/web/ostatus/activity_representer.ex b/lib/pleroma/web/ostatus/activity_representer.ex @@ -184,7 +184,10 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenter do retweeted_xml = to_simple_form(retweeted_activity, retweeted_user, true) - mentions = activity.recipients |> get_mentions + mentions = + ([retweeted_user.ap_id] ++ activity.recipients) + |> Enum.uniq() + |> get_mentions() [ {:"activity:object-type", ['http://activitystrea.ms/schema/1.0/activity']},