publisher: move remote_users() from Salmon module
authorAriadne Conill <ariadne@dereferenced.org>
Thu, 17 Oct 2019 23:05:45 +0000 (23:05 +0000)
committerAriadne Conill <ariadne@dereferenced.org>
Fri, 18 Oct 2019 14:50:09 +0000 (14:50 +0000)
lib/pleroma/web/activity_pub/publisher.ex
lib/pleroma/web/federator/publisher.ex

index 3866daceee4b57a1e8ddf049aaa3b8653bb47cd5..2aac4e8b92ad90291d5682df73ed4e5642dd7415 100644 (file)
@@ -129,7 +129,7 @@ defmodule Pleroma.Web.ActivityPub.Publisher do
           []
       end
 
-    Pleroma.Web.Salmon.remote_users(actor, activity) ++ followers ++ fetchers
+    Pleroma.Web.Federator.Publisher.remote_users(actor, activity) ++ followers ++ fetchers
   end
 
   defp get_cc_ap_ids(ap_id, recipients) do
index 937064638fc72ee9d8d1b21b80ac34656e17fc89..fb9b26649b5a3a0dff1b3c60907fb244a970ac71 100644 (file)
@@ -80,4 +80,30 @@ defmodule Pleroma.Web.Federator.Publisher do
       links ++ module.gather_nodeinfo_protocol_names()
     end)
   end
+
+  @doc """
+  Gathers a set of remote users given an IR envelope.
+  """
+  def remote_users(%User{id: user_id}, %{data: %{"to" => to} = data}) do
+    cc = Map.get(data, "cc", [])
+
+    bcc =
+      data
+      |> Map.get("bcc", [])
+      |> Enum.reduce([], fn ap_id, bcc ->
+        case Pleroma.List.get_by_ap_id(ap_id) do
+          %Pleroma.List{user_id: ^user_id} = list ->
+            {:ok, following} = Pleroma.List.get_following(list)
+            bcc ++ Enum.map(following, & &1.ap_id)
+
+          _ ->
+            bcc
+        end
+      end)
+
+    [to, cc, bcc]
+    |> Enum.concat()
+    |> Enum.map(&User.get_cached_by_ap_id/1)
+    |> Enum.filter(fn user -> user && !user.local end)
+  end
 end