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
@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