Conversation: Add accounts to output.
This commit is contained in:
parent
0da985182f
commit
76999c73a7
5 changed files with 23 additions and 3 deletions
|
@ -13,6 +13,7 @@ defmodule Pleroma.Conversation do
|
||||||
# This is the context ap id.
|
# This is the context ap id.
|
||||||
field(:ap_id, :string)
|
field(:ap_id, :string)
|
||||||
has_many(:participations, Participation)
|
has_many(:participations, Participation)
|
||||||
|
has_many(:users, through: [:participations, :user])
|
||||||
|
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
|
@ -60,6 +60,7 @@ def for_user(user, params \\ %{}) do
|
||||||
order_by: [desc: p.updated_at]
|
order_by: [desc: p.updated_at]
|
||||||
)
|
)
|
||||||
|> Pleroma.Pagination.fetch_paginated(params)
|
|> Pleroma.Pagination.fetch_paginated(params)
|
||||||
|
|> Repo.preload(conversation: [:users])
|
||||||
end
|
end
|
||||||
|
|
||||||
def for_user_with_last_activity_id(user, params \\ %{}) do
|
def for_user_with_last_activity_id(user, params \\ %{}) do
|
||||||
|
|
|
@ -1594,10 +1594,15 @@ def conversations(%{assigns: %{user: user}} = conn, params) do
|
||||||
|
|
||||||
last_status = StatusView.render("status.json", %{activity: activity, for: user})
|
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(),
|
id: participation.id |> to_string(),
|
||||||
# TODO: Add this.
|
accounts: accounts,
|
||||||
accounts: [],
|
|
||||||
unread: !participation.read,
|
unread: !participation.read,
|
||||||
last_status: last_status
|
last_status: last_status
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ test "it creates or updates a conversation and participations for a given DM" do
|
||||||
|
|
||||||
conversation_three =
|
conversation_three =
|
||||||
Conversation.get_for_ap_id(context)
|
Conversation.get_for_ap_id(context)
|
||||||
|> Repo.preload(:participations)
|
|> Repo.preload([:participations, :users])
|
||||||
|
|
||||||
assert conversation_three.id == conversation.id
|
assert conversation_three.id == conversation.id
|
||||||
|
|
||||||
|
@ -100,5 +100,17 @@ test "it creates or updates a conversation and participations for a given DM" do
|
||||||
assert Enum.find(conversation_three.participations, fn %{user_id: user_id} ->
|
assert Enum.find(conversation_three.participations, fn %{user_id: user_id} ->
|
||||||
tridi.id == user_id
|
tridi.id == user_id
|
||||||
end)
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -334,6 +334,7 @@ test "Conversations", %{conn: conn} do
|
||||||
}
|
}
|
||||||
] = response
|
] = response
|
||||||
|
|
||||||
|
assert length(res_accounts) == 2
|
||||||
assert is_binary(res_id)
|
assert is_binary(res_id)
|
||||||
assert unread == true
|
assert unread == true
|
||||||
assert res_last_status["id"] == direct.id
|
assert res_last_status["id"] == direct.id
|
||||||
|
|
Loading…
Reference in a new issue