aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Chvanikov <chvanikoff@gmail.com>2019-04-21 20:26:13 +0700
committerRoman Chvanikov <chvanikoff@gmail.com>2019-04-21 20:26:13 +0700
commit2662bea4e0d945edf7a24a44edf3ed39b2e64de9 (patch)
tree96f38ab157d2fd2f9db5c5822a886918de333efe
parent24073f829f18d1ebd2cb23dd815c775b39145e42 (diff)
downloadpleroma-2662bea4e0d945edf7a24a44edf3ed39b2e64de9.tar.gz
Add accounts and last_status to conversation read response
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api_controller.ex24
-rw-r--r--test/web/mastodon_api/mastodon_api_controller_test.exs2
2 files changed, 22 insertions, 4 deletions
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index c7166ff28..86cacb0b0 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -1617,14 +1617,30 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
with %Participation{} = participation <-
Repo.get_by(Participation, id: participation_id, user_id: user.id),
{:ok, participation} <- Participation.mark_as_read(participation) do
+ participation = Repo.preload(participation, conversation: :users)
+
+ accounts =
+ AccountView.render("accounts.json", %{
+ users: participation.conversation.users,
+ as: :user
+ })
+
+ last_activity_id =
+ ActivityPub.fetch_latest_activity_id_for_context(participation.conversation.ap_id, %{
+ "user" => user,
+ "blocking_user" => user
+ })
+
+ activity = Activity.get_by_id_with_object(last_activity_id)
+
+ last_status = StatusView.render("status.json", %{activity: activity, for: user})
+
conn
|> json(%{
id: participation.id,
- # TODO: Add this.
- accounts: [],
+ accounts: accounts,
unread: !participation.read,
- # TODO: Add this.
- last_status: nil
+ last_status: last_status
})
end
end
diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs
index 4fa5254f3..cf77dff78 100644
--- a/test/web/mastodon_api/mastodon_api_controller_test.exs
+++ b/test/web/mastodon_api/mastodon_api_controller_test.exs
@@ -346,6 +346,8 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|> post("/api/v1/conversations/#{res_id}/read")
assert response = json_response(res_conn, 200)
+ assert length(response["accounts"]) == 2
+ assert response["last_status"]["id"] == direct.id
assert response["unread"] == false
# (vanilla) Mastodon frontend behaviour