Update mastodon_api_controller.ex
[akkoma] / lib / pleroma / user.ex
index 3bcfcdd918e8741f40df2c4c2dc7c301b3abe6a7..64c69b209cddc9ae339f4e1a13b2aad6d6361d87 100644 (file)
@@ -68,7 +68,8 @@ defmodule Pleroma.User do
       following_count: length(user.following) - oneself,
       note_count: user.info["note_count"] || 0,
       follower_count: user.info["follower_count"] || 0,
-      locked: user.info["locked"] || false
+      locked: user.info["locked"] || false,
+      default_scope: user.info["default_scope"] || "public"
     }
   end
 
@@ -457,13 +458,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