From: lain Date: Wed, 27 Feb 2019 15:52:03 +0000 (+0100) Subject: Add user muted status info to twitterapi. X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=9ade1242c20acae5d27785deb833b453628b12ee;p=akkoma Add user muted status info to twitterapi. --- diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex index 661022afa..02ca4ee42 100644 --- a/lib/pleroma/web/twitter_api/views/activity_view.ex +++ b/lib/pleroma/web/twitter_api/views/activity_view.ex @@ -10,6 +10,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do alias Pleroma.Object alias Pleroma.Repo alias Pleroma.User + alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI.Utils alias Pleroma.Web.MastodonAPI.StatusView alias Pleroma.Web.TwitterAPI.ActivityView @@ -309,7 +310,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do "visibility" => StatusView.get_visibility(object), "summary" => summary, "summary_html" => summary |> Formatter.emojify(object["emoji"]), - "card" => card + "card" => card, + "muted" => CommonAPI.thread_muted?(user, activity) || User.mutes?(opts[:for], user) } end diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index 4f854ecaa..0a5384f34 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -56,6 +56,22 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do assert result["user"]["id"] == user.id 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 = ActivityView.render("activity.json", %{activity: activity}) + + assert status["muted"] == false + + status = ActivityView.render("activity.json", %{activity: activity, for: user}) + + assert status["muted"] == true + end + test "a create activity with a html status" do text = """ #Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg @@ -149,7 +165,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do "uri" => activity.data["object"]["id"], "user" => UserView.render("show.json", %{user: user}), "visibility" => "direct", - "card" => nil + "card" => nil, + "muted" => false } assert result == expected