activity: add recipients_to and recipients_cc fields
authorWilliam Pitcock <nenolod@dereferenced.org>
Wed, 29 Aug 2018 08:37:36 +0000 (08:37 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Wed, 29 Aug 2018 08:42:33 +0000 (08:42 +0000)
lib/pleroma/activity.ex
lib/pleroma/web/activity_pub/activity_pub.ex
priv/repo/migrations/20180829082446_add_recipients_to_and_cc_fields_to_activities.exs [new file with mode: 0644]

index bed96861f893043f8651401fb6cc268aa91c2d5a..4f1f8292dc13408d99b7f5cf2c52195118e8e1a2 100644 (file)
@@ -8,6 +8,8 @@ defmodule Pleroma.Activity do
     field(:local, :boolean, default: true)
     field(:actor, :string)
     field(:recipients, {:array, :string})
+    field(:recipients_to, {:array, :string})
+    field(:recipients_cc, {:array, :string})
     has_many(:notifications, Notification, on_delete: :delete_all)
 
     timestamps()
index 68b3987866f71ea97f2896e7a2379ac322451987..fdbd7fed00404ca8c787fad71a17f1c977ac6400 100644 (file)
@@ -14,8 +14,10 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
 
   # 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"] || [])
+  defp get_recipients(%{"type" => "Announce"} = data) do
+    to = data["to"] || []
+    cc = data["cc"] || []
+    recipients = to ++ cc
     actor = User.get_cached_by_ap_id(data["actor"])
 
     recipients
@@ -28,10 +30,15 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
           User.following?(user, actor)
       end
     end)
+
+    {recipients, to, cc}
   end
 
-  def get_recipients(data) do
-    (data["to"] || []) ++ (data["cc"] || [])
+  defp get_recipients(data) do
+    to = data["to"] || []
+    cc = data["cc"] || []
+    recipients = to ++ cc
+    {recipients, to, cc}
   end
 
   defp check_actor_is_active(actor) do
@@ -53,12 +60,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
          :ok <- check_actor_is_active(map["actor"]),
          {:ok, map} <- MRF.filter(map),
          :ok <- insert_full_object(map) do
+      {recipients, recipients_to, recipients_cc} = get_recipients(map)
+
       {:ok, activity} =
         Repo.insert(%Activity{
           data: map,
           local: local,
           actor: map["actor"],
-          recipients: get_recipients(map)
+          recipients: recipients,
+          recipients_to: recipients_to,
+          recipients_cc: recipients_cc
         })
 
       Notification.create_notifications(activity)
diff --git a/priv/repo/migrations/20180829082446_add_recipients_to_and_cc_fields_to_activities.exs b/priv/repo/migrations/20180829082446_add_recipients_to_and_cc_fields_to_activities.exs
new file mode 100644 (file)
index 0000000..96af412
--- /dev/null
@@ -0,0 +1,13 @@
+defmodule Pleroma.Repo.Migrations.AddRecipientsToAndCcFieldsToActivities do
+  use Ecto.Migration
+
+  def change do
+    alter table(:activities) do
+      add :recipients_to, {:array, :string}
+      add :recipients_cc, {:array, :string}
+    end
+
+    create index(:activities, [:recipients_to], using: :gin)
+    create index(:activities, [:recipients_cc], using: :gin)
+  end
+end