Commit c37118e6 authored by lain's avatar lain
Browse files

Conversations: A few refactors

parent 91f6c324
......@@ -34,7 +34,8 @@ def render("participation.json", %{participation: participation, for: user}) 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
# Conversations return all users except the current user,
# except when the current user is the only participant
users =
if length(participation.recipients) > 1 do
Enum.reject(participation.recipients, &(&1.id == user.id))
......
......@@ -65,12 +65,11 @@ test "returns correct conversations", %{
assert Participation.unread_count(user_one) == 0
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_two: user_two,
conn: conn
} do
{:ok, direct} = create_direct_message(user_one, [])
{:ok, _direct} = create_direct_message(user_one, [])
res_conn = get(conn, "/api/v1/conversations")
......@@ -78,14 +77,11 @@ test "special behaviour when conversation have only one user", %{
assert [
%{
"accounts" => res_accounts,
"last_status" => res_last_status
"accounts" => [account]
}
] = response
account_ids = Enum.map(res_accounts, & &1["id"])
assert length(res_accounts) == 1
assert user_one.id in account_ids
assert user_one.id == account["id"]
end
test "observes limit params", %{
......
......@@ -38,9 +38,9 @@ test "represents a Mastodon Conversation entity" do
assert conversation.last_status.id == activity.id
assert conversation.last_status.account.id == user.id
account_ids = Enum.map(conversation.accounts, & &1.id)
assert length(conversation.accounts) == 1
assert other_user.id in account_ids
assert [account] = conversation.accounts
assert account.id == other_user.id
assert conversation.last_status.pleroma.direct_conversation_id == participation.id
end
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment