refactor filtering mechanism
authorKaren Konou <konoukaren@gmail.com>
Mon, 11 Mar 2019 15:57:54 +0000 (16:57 +0100)
committerKaren Konou <konoukaren@gmail.com>
Fri, 15 Mar 2019 13:18:53 +0000 (14:18 +0100)
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
lib/pleroma/web/streamer.ex

index 779ee139b0984bc71d75cd8e91a0c89fb1f81e54..5d9ce7fd744a644288a41e035bc9f958884a7e4e 100644 (file)
@@ -679,6 +679,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
 
   defp restrict_pinned(query, _), do: query
 
+  defp restrict_muted_reblogs(query, %{"muting_user" => %User{info: info}}) do
+    muted_reblogs = info.muted_reblogs || []
+
+    from(
+      activity in query,
+      where: fragment("not ?->>'type' = 'Announce'", activity.data),
+      where: fragment("not ? = ANY(?)", activity.actor, ^muted_reblogs)
+    )
+  end
+
+  defp restrict_muted_reblogs(query, _), do: query
+
   def fetch_activities_query(recipients, opts \\ %{}) do
     base_query =
       from(
@@ -706,6 +718,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     |> restrict_replies(opts)
     |> restrict_reblogs(opts)
     |> restrict_pinned(opts)
+    |> restrict_muted_reblogs(opts)
   end
 
   def fetch_activities(recipients, opts \\ %{}) do
@@ -951,17 +964,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     entire_thread_visible_for_user?(activity, user)
   end
 
-  # filter out muted threads
-  def contain_muted_boosts(%Activity{data: %{"type" => "Announce"}} = activity, %User{} = user) do
-    id = User.get_by_ap_id(activity.actor).id
-    id not in user.info.muted_reblogs
-  end
-
   def contain_muted_boosts(%Activity{} = _activity, %User{} = _user), do: true
 
   # do post-processing on a specific activity
   def contain_activity(%Activity{} = activity, %User{} = user) do
-    contain_broken_threads(activity, user) and contain_muted_boosts(activity, user)
+    contain_broken_threads(activity, user)
   end
 
   # do post-processing on a timeline
index 570bf0c0f92dc23fdbeccbe6fef6ffd071675e17..68b7d8b49dd62ffc67857ad25218c98b597d1c95 100644 (file)
@@ -735,7 +735,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
           false -> CommonAPI.hide_reblogs(follower, id)
         end
 
-        followed = Repo.get(User, id)
+        followed = User.get_cached_by_id(id)
 
         conn
         |> put_view(AccountView)
index a04ee1b6ebf934815b9ba3c4540c6dc50aef1671..b87db941bb51b3606ab3e76e421799c2b6fe25c1 100644 (file)
@@ -200,10 +200,12 @@ defmodule Pleroma.Web.Streamer do
         user = User.get_cached_by_ap_id(socket.assigns[:user].ap_id)
         blocks = user.info.blocks || []
         mutes = user.info.mutes || []
+        reblog_mutes = user.info.reblog_mutes || []
 
         parent = Object.normalize(item.data["object"])
 
         unless is_nil(parent) or item.actor in blocks or item.actor in mutes or
+                 item.actor in reblog_mutes or
                  not ActivityPub.contain_activity(item, user) or parent.data["actor"] in blocks or
                  parent.data["actor"] in mutes do
           send(socket.transport_pid, {:text, represent_update(item, user)})