Add user muted status info to MastodonAPI.
authorlain <lain@soykaf.club>
Wed, 27 Feb 2019 15:46:47 +0000 (16:46 +0100)
committerlain <lain@soykaf.club>
Wed, 27 Feb 2019 15:46:47 +0000 (16:46 +0100)
lib/pleroma/user.ex
lib/pleroma/web/mastodon_api/views/status_view.ex
test/web/mastodon_api/status_view_test.exs

index 01d532ab3158b3060e26a3fb0d3d69f6c37c5bcc..3a8a51e33d875324bf0bb271446ce0f0adf9f746 100644 (file)
@@ -960,6 +960,7 @@ defmodule Pleroma.User do
     update_and_set_cache(cng)
   end
 
+  def mutes?(nil, _), do: false
   def mutes?(user, %{ap_id: ap_id}), do: Enum.member?(user.info.mutes, ap_id)
 
   def blocks?(user, %{ap_id: ap_id}) do
index b90e4252a3ab43c7d96e728ad5d601be57860a89..3468c0e1c1bd1c6f61c75819d92fdda79eb56344 100644 (file)
@@ -168,7 +168,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
       reblogged: present?(repeated),
       favourited: present?(favorited),
       bookmarked: present?(bookmarked),
-      muted: CommonAPI.thread_muted?(user, activity),
+      muted: CommonAPI.thread_muted?(user, activity) || User.mutes?(opts[:for], user),
       pinned: pinned?(activity, user),
       sensitive: sensitive,
       spoiler_text: object["summary"] || "",
index 3412a6be2e0c81550fc4f6ee397ebdd2b7e93f69..351dbf673e421c4549024a5cac1a4f84702dd72a 100644 (file)
@@ -126,6 +126,22 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
     assert status == expected
   end
 
+  test "tells if the message is muted for some reason" do
+    user = insert(:user)
+    other_user = insert(:user)
+
+    {:ok, user} = User.mute(user, other_user)
+
+    {:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"})
+    status = StatusView.render("status.json", %{activity: activity})
+
+    assert status.muted == false
+
+    status = StatusView.render("status.json", %{activity: activity, for: user})
+
+    assert status.muted == true
+  end
+
   test "a reply" do
     note = insert(:note_activity)
     user = insert(:user)