From 76999c73a790232ff0c30fff7a51589fb44651a3 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 15 Apr 2019 22:28:42 +0200 Subject: [PATCH] Conversation: Add accounts to output. --- lib/pleroma/conversation.ex | 1 + lib/pleroma/conversation/participation.ex | 1 + lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 9 +++++++-- test/conversation_test.exs | 14 +++++++++++++- test/web/mastodon_api/mastodon_api_controller_test.exs | 1 + 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/conversation.ex b/lib/pleroma/conversation.ex index 5a2a3fc6d..d9c84cb1b 100644 --- a/lib/pleroma/conversation.ex +++ b/lib/pleroma/conversation.ex @@ -13,6 +13,7 @@ defmodule Pleroma.Conversation do # This is the context ap id. field(:ap_id, :string) has_many(:participations, Participation) + has_many(:users, through: [:participations, :user]) timestamps() end diff --git a/lib/pleroma/conversation/participation.ex b/lib/pleroma/conversation/participation.ex index 1a2ceafeb..f200c1df5 100644 --- a/lib/pleroma/conversation/participation.ex +++ b/lib/pleroma/conversation/participation.ex @@ -60,6 +60,7 @@ defmodule Pleroma.Conversation.Participation do order_by: [desc: p.updated_at] ) |> Pleroma.Pagination.fetch_paginated(params) + |> Repo.preload(conversation: [:users]) end def for_user_with_last_activity_id(user, params \\ %{}) do diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 3ffb767b9..c7166ff28 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1594,10 +1594,15 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do last_status = StatusView.render("status.json", %{activity: activity, for: user}) + accounts = + AccountView.render("accounts.json", %{ + users: participation.conversation.users, + as: :user + }) + %{ id: participation.id |> to_string(), - # TODO: Add this. - accounts: [], + accounts: accounts, unread: !participation.read, last_status: last_status } diff --git a/test/conversation_test.exs b/test/conversation_test.exs index 150d55631..239dda04f 100644 --- a/test/conversation_test.exs +++ b/test/conversation_test.exs @@ -85,7 +85,7 @@ defmodule Pleroma.ConversationTest do conversation_three = Conversation.get_for_ap_id(context) - |> Repo.preload(:participations) + |> Repo.preload([:participations, :users]) assert conversation_three.id == conversation.id @@ -100,5 +100,17 @@ defmodule Pleroma.ConversationTest do assert Enum.find(conversation_three.participations, fn %{user_id: user_id} -> tridi.id == user_id end) + + assert Enum.find(conversation_three.users, fn %{id: user_id} -> + har.id == user_id + end) + + assert Enum.find(conversation_three.users, fn %{id: user_id} -> + jafnhar.id == user_id + end) + + assert Enum.find(conversation_three.users, fn %{id: user_id} -> + tridi.id == user_id + end) 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 bd13f870c..4fa5254f3 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -334,6 +334,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do } ] = response + assert length(res_accounts) == 2 assert is_binary(res_id) assert unread == true assert res_last_status["id"] == direct.id