Fix Mastodon API when actor's nickname is null
[akkoma] / lib / pleroma / user.ex
index 3bcfcdd918e8741f40df2c4c2dc7c301b3abe6a7..fca490cb1843c6227d6e8013c1d5962a02929370 100644 (file)
@@ -457,13 +457,34 @@ 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"])
+    actor = User.get_cached_by_ap_id(data["actor"])
+
+    # ensure that the actor who published the announced object appears only once
+    to =
+      if actor.nickname != nil do
+        to ++ [object.data["actor"]]
+      else
+        to
+      end
+      |> 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