Misc refactoring / tweaks (`ThreadMute.exists?/2`).
authorIvan Tashkinov <ivantashkinov@gmail.com>
Fri, 27 Mar 2020 05:01:03 +0000 (08:01 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Fri, 27 Mar 2020 05:01:03 +0000 (08:01 +0300)
lib/pleroma/thread_mute.ex
lib/pleroma/web/common_api/common_api.ex
lib/pleroma/web/mastodon_api/views/notification_view.ex
lib/pleroma/web/mastodon_api/views/status_view.ex
test/web/mastodon_api/views/account_view_test.exs

index 5768e77111915df56e0942db89c3014bf36bc327..be01d541dab5ef977e1950fd08f63b33834c631e 100644 (file)
@@ -68,8 +68,8 @@ defmodule Pleroma.ThreadMute do
     |> Repo.delete_all()
   end
 
-  def check_muted(user_id, context) do
+  def exists?(user_id, context) do
     query(user_id, context)
-    |> Repo.all()
+    |> Repo.exists?()
   end
 end
index 091011c6b1082abf268221c2b80c2a4169e66cf8..2646b9f7b8887c31cc685e54c4c3a68be15da0c6 100644 (file)
@@ -358,7 +358,7 @@ defmodule Pleroma.Web.CommonAPI do
   def thread_muted?(%{id: nil} = _user, _activity), do: false
 
   def thread_muted?(user, activity) do
-    ThreadMute.check_muted(user.id, activity.data["context"]) != []
+    ThreadMute.exists?(user.id, activity.data["context"])
   end
 
   def report(user, %{"account_id" => account_id} = data) do
index a809080fd17f8f74c8d97f8ed65393becef55154..89f5734ffaee84d618dd260fc18f5b5798b3ba12 100644 (file)
@@ -98,27 +98,27 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
         }
       }
 
-      relationships_opt = %{relationships: opts[:relationships]}
+      render_opts = %{relationships: opts[:relationships]}
 
       case mastodon_type do
         "mention" ->
-          put_status(response, activity, reading_user, relationships_opt)
+          put_status(response, activity, reading_user, render_opts)
 
         "favourite" ->
-          put_status(response, parent_activity_fn.(), reading_user, relationships_opt)
+          put_status(response, parent_activity_fn.(), reading_user, render_opts)
 
         "reblog" ->
-          put_status(response, parent_activity_fn.(), reading_user, relationships_opt)
+          put_status(response, parent_activity_fn.(), reading_user, render_opts)
 
         "move" ->
-          put_target(response, activity, reading_user, relationships_opt)
+          put_target(response, activity, reading_user, render_opts)
 
         "follow" ->
           response
 
         "pleroma:emoji_reaction" ->
           response
-          |> put_status(parent_activity_fn.(), reading_user, relationships_opt)
+          |> put_status(parent_activity_fn.(), reading_user, render_opts)
           |> put_emoji(activity)
 
         _ ->
index d36b9ee5c49b456711cd0467e95e085806b9c48b..440eef4baf3de503938e9c00fb3c6247453c5b2d 100644 (file)
@@ -228,9 +228,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
       end
 
     thread_muted? =
-      case activity.thread_muted? do
-        thread_muted? when is_boolean(thread_muted?) -> thread_muted?
-        nil -> (opts[:for] && CommonAPI.thread_muted?(opts[:for], activity)) || false
+      cond do
+        is_nil(opts[:for]) -> false
+        is_boolean(activity.thread_muted?) -> activity.thread_muted?
+        true -> CommonAPI.thread_muted?(opts[:for], activity)
       end
 
     attachment_data = object.data["attachment"] || []
index ede62903f9e27cc820be49d07cece81ddbb221eb..0d1c3ecb3fc5cacaf1a58a66106e8ebe78873637 100644 (file)
@@ -186,7 +186,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
 
   describe "relationship" do
     defp test_relationship_rendering(user, other_user, expected_result) do
-      opts = %{user: user, target: other_user}
+      opts = %{user: user, target: other_user, relationships: nil}
       assert expected_result == AccountView.render("relationship.json", opts)
 
       relationships_opt = UserRelationship.view_relationships_option(user, [other_user])