Conversations: A few refactors

This commit is contained in:
lain 2020-11-03 13:56:12 +01:00
parent 91f6c32430
commit c37118e6f2
3 changed files with 9 additions and 12 deletions

View File

@ -34,7 +34,8 @@ def render("participation.json", %{participation: participation, for: user}) do
activity = Activity.get_by_id_with_object(last_activity_id) activity = Activity.get_by_id_with_object(last_activity_id)
# Conversations return all users except current user when current user is not only participant # Conversations return all users except the current user,
# except when the current user is the only participant
users = users =
if length(participation.recipients) > 1 do if length(participation.recipients) > 1 do
Enum.reject(participation.recipients, &(&1.id == user.id)) Enum.reject(participation.recipients, &(&1.id == user.id))

View File

@ -65,12 +65,11 @@ test "returns correct conversations", %{
assert Participation.unread_count(user_one) == 0 assert Participation.unread_count(user_one) == 0
end end
test "special behaviour when conversation have only one user", %{ test "includes the user if the user is the only participant", %{
user: user_one, user: user_one,
user_two: user_two,
conn: conn conn: conn
} do } do
{:ok, direct} = create_direct_message(user_one, []) {:ok, _direct} = create_direct_message(user_one, [])
res_conn = get(conn, "/api/v1/conversations") res_conn = get(conn, "/api/v1/conversations")
@ -78,14 +77,11 @@ test "special behaviour when conversation have only one user", %{
assert [ assert [
%{ %{
"accounts" => res_accounts, "accounts" => [account]
"last_status" => res_last_status
} }
] = response ] = response
account_ids = Enum.map(res_accounts, & &1["id"]) assert user_one.id == account["id"]
assert length(res_accounts) == 1
assert user_one.id in account_ids
end end
test "observes limit params", %{ test "observes limit params", %{

View File

@ -38,9 +38,9 @@ test "represents a Mastodon Conversation entity" do
assert conversation.last_status.id == activity.id assert conversation.last_status.id == activity.id
assert conversation.last_status.account.id == user.id assert conversation.last_status.account.id == user.id
account_ids = Enum.map(conversation.accounts, & &1.id) assert [account] = conversation.accounts
assert length(conversation.accounts) == 1 assert account.id == other_user.id
assert other_user.id in account_ids
assert conversation.last_status.pleroma.direct_conversation_id == participation.id assert conversation.last_status.pleroma.direct_conversation_id == participation.id
end end
end end