Conversation: Add accounts to output.
authorlain <lain@soykaf.club>
Mon, 15 Apr 2019 20:28:42 +0000 (22:28 +0200)
committerlain <lain@soykaf.club>
Mon, 15 Apr 2019 20:28:42 +0000 (22:28 +0200)
lib/pleroma/conversation.ex
lib/pleroma/conversation/participation.ex
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
test/conversation_test.exs
test/web/mastodon_api/mastodon_api_controller_test.exs

index 5a2a3fc6de302ff0e311918532c679f4c58c5261..d9c84cb1b62d4375770b9f45726457ce29f59f02 100644 (file)
@@ -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
index 1a2ceafeb2a819ec23f3984e7fd10475e2dfc782..f200c1df56698495f49cac149daeb95a527f238d 100644 (file)
@@ -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
index 3ffb767b912faa2849a1c933fdfb65efff51a57c..c7166ff289cbe11d34b8e9eacddde422f596a80b 100644 (file)
@@ -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
         }
index 150d55631d884a29a0eedb62cb3d83493b1d1c41..239dda04f0716adbf9512722058c886d1469e94e 100644 (file)
@@ -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
index bd13f870c5a85f773ac2fada7db0946f38093588..4fa5254f3cd538254ca47ba05c35108aa691827f 100644 (file)
@@ -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