[#1335] Reorganized `users.mutes` as relation to UserMute entity.
[akkoma] / lib / pleroma / web / activity_pub / activity_pub.ex
index 65dd251f3ea3ddb62ab6b5fa2460e41db288e162..cba2abfc37314db5b664cdc6597036c69e7138c1 100644 (file)
@@ -858,7 +858,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
   defp restrict_muted(query, %{"with_muted" => val}) when val in [true, "true", "1"], do: query
 
   defp restrict_muted(query, %{"muting_user" => %User{} = user} = opts) do
-    mutes = user.mutes
+    mutes = opts["muted_ap_ids"] || User.muted_ap_ids(user)
 
     query =
       from([activity] in query,
@@ -875,8 +875,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
 
   defp restrict_muted(query, _), do: query
 
-  defp restrict_blocked(query, %{"blocking_user" => %User{} = user}) do
-    blocks = user.blocks || []
+  defp restrict_blocked(query, %{"blocking_user" => %User{} = user} = opts) do
+    blocked_ap_ids = opts["blocked_ap_ids"] || User.blocked_ap_ids(user)
     domain_blocks = user.domain_blocks || []
 
     query =
@@ -884,14 +884,14 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
 
     from(
       [activity, object: o] in query,
-      where: fragment("not (? = ANY(?))", activity.actor, ^blocks),
-      where: fragment("not (? && ?)", activity.recipients, ^blocks),
+      where: fragment("not (? = ANY(?))", activity.actor, ^blocked_ap_ids),
+      where: fragment("not (? && ?)", activity.recipients, ^blocked_ap_ids),
       where:
         fragment(
           "not (?->>'type' = 'Announce' and ?->'to' \\?| ?)",
           activity.data,
           activity.data,
-          ^blocks
+          ^blocked_ap_ids
         ),
       where: fragment("not (split_part(?, '/', 3) = ANY(?))", activity.actor, ^domain_blocks),
       where: fragment("not (split_part(?->>'actor', '/', 3) = ANY(?))", o.data, ^domain_blocks)