aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlain <lain@soykaf.club>2019-02-27 16:46:47 +0100
committerlain <lain@soykaf.club>2019-02-27 16:46:47 +0100
commitc1ae495878cc95d09a051cc56e2bf7dc7ed0a032 (patch)
treebe4bd948be6a8d0fdac6ba349a35671eae0d6f9d
parentc4235f96bde49def1fb6927ba79a49a0f75cd60a (diff)
downloadpleroma-c1ae495878cc95d09a051cc56e2bf7dc7ed0a032.tar.gz
Add user muted status info to MastodonAPI.
-rw-r--r--lib/pleroma/user.ex1
-rw-r--r--lib/pleroma/web/mastodon_api/views/status_view.ex2
-rw-r--r--test/web/mastodon_api/status_view_test.exs16
3 files changed, 18 insertions, 1 deletions
diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex
index 01d532ab3..3a8a51e33 100644
--- a/lib/pleroma/user.ex
+++ b/lib/pleroma/user.ex
@@ -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
diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex
index b90e4252a..3468c0e1c 100644
--- a/lib/pleroma/web/mastodon_api/views/status_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/status_view.ex
@@ -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"] || "",
diff --git a/test/web/mastodon_api/status_view_test.exs b/test/web/mastodon_api/status_view_test.exs
index 3412a6be2..351dbf673 100644
--- a/test/web/mastodon_api/status_view_test.exs
+++ b/test/web/mastodon_api/status_view_test.exs
@@ -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)