ConversationView: fix last_status.account being empty, fix current user being included in group conversations
This commit is contained in:
parent
630eb0f939
commit
9b93eef715
@ -34,14 +34,22 @@ defmodule Pleroma.Web.MastodonAPI.ConversationView do
|
||||
|
||||
activity = Activity.get_by_id_with_object(last_activity_id)
|
||||
|
||||
# Conversations return all users except current user when current user is not only participant
|
||||
users = if length(participation.recipients) > 1 do
|
||||
Enum.reject(participation.recipients, &(&1.id == user.id))
|
||||
else
|
||||
participation.recipients
|
||||
end
|
||||
|
||||
%{
|
||||
id: participation.id |> to_string(),
|
||||
accounts: render(AccountView, "index.json", users: participation.recipients, for: user),
|
||||
accounts: render(AccountView, "index.json", users: users, for: user),
|
||||
unread: !participation.read,
|
||||
last_status:
|
||||
render(StatusView, "show.json",
|
||||
activity: activity,
|
||||
direct_conversation_id: participation.id
|
||||
direct_conversation_id: participation.id,
|
||||
for: user
|
||||
)
|
||||
}
|
||||
end
|
||||
|
@ -54,16 +54,37 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
||||
] = response
|
||||
|
||||
account_ids = Enum.map(res_accounts, & &1["id"])
|
||||
assert length(res_accounts) == 3
|
||||
assert user_one.id in account_ids
|
||||
assert length(res_accounts) == 2
|
||||
assert user_one.id not in account_ids
|
||||
assert user_two.id in account_ids
|
||||
assert user_three.id in account_ids
|
||||
assert is_binary(res_id)
|
||||
assert unread == false
|
||||
assert res_last_status["id"] == direct.id
|
||||
assert res_last_status["account"]["id"] == user_one.id
|
||||
assert Participation.unread_count(user_one) == 0
|
||||
end
|
||||
|
||||
test "special behaviour when conversation have only one user", %{
|
||||
user: user_one,
|
||||
user_two: user_two,
|
||||
conn: conn
|
||||
} do
|
||||
{:ok, direct} = create_direct_message(user_one, [])
|
||||
|
||||
res_conn = get(conn, "/api/v1/conversations")
|
||||
|
||||
assert response = json_response_and_validate_schema(res_conn, 200)
|
||||
assert [
|
||||
%{
|
||||
"accounts" => res_accounts,
|
||||
"last_status" => res_last_status
|
||||
}
|
||||
] = response
|
||||
assert length(res_accounts) == 1
|
||||
assert res_accounts[0]["id"] == user_one.id
|
||||
end
|
||||
|
||||
test "observes limit params", %{
|
||||
user: user_one,
|
||||
user_two: user_two,
|
||||
|
Loading…
Reference in New Issue
Block a user