activitypub: transmogrifier: unify mention extraction
authorWilliam Pitcock <nenolod@dereferenced.org>
Thu, 8 Nov 2018 19:31:59 +0000 (19:31 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Thu, 8 Nov 2018 19:41:36 +0000 (19:41 +0000)
lib/pleroma/user.ex
lib/pleroma/web/activity_pub/transmogrifier.ex
lib/pleroma/web/activity_pub/utils.ex

index acb355a052503d34b98c28c289db6a7ecd5805dc..260d904bcf65bd59800ac9572de8a80a598b3bd4 100644 (file)
@@ -482,7 +482,10 @@ defmodule Pleroma.User do
 
   def get_notified_from_activity(activity, local_only \\ true)
 
-  def get_notified_from_activity(%Activity{data: %{"type" => "Announce", "to" => to} = data}, local_only) do
+  def get_notified_from_activity(
+        %Activity{data: %{"type" => "Announce", "to" => to} = data},
+        local_only
+      ) do
     object = Object.normalize(data["object"])
     actor = User.get_cached_by_ap_id(data["actor"])
 
index 1471c9416ac2404e71cf843e57be210645a4814c..6a0fdb433098484bca261e94fdb94fec5eed130a 100644 (file)
@@ -693,12 +693,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
   end
 
   def add_mention_tags(object) do
-    recipients = object["to"] || []
-
     mentions =
-      recipients
-      |> Enum.map(fn ap_id -> User.get_cached_by_ap_id(ap_id) end)
-      |> Enum.filter(& &1)
+      object
+      |> Utils.get_notified_from_object()
       |> Enum.map(fn user ->
         %{"type" => "Mention", "href" => user.ap_id, "name" => "@#{user.nickname}"}
       end)
index d81c824f077e0214fcb2c570b2a4a58bbfdb131d..fd9c5eb59e8a26f9b3c53f022c0b1ab0dd7ec0b5 100644 (file)
@@ -95,6 +95,10 @@ defmodule Pleroma.Web.ActivityPub.Utils do
     "#{Web.base_url()}/#{type}/#{UUID.generate()}"
   end
 
+  def get_notified_from_object(object) do
+    User.get_notified_from_activity(%Activity{data: object}, false)
+  end
+
   def create_context(context) do
     context = context || generate_id("contexts")
     changeset = Object.context_mapping(context)