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)
# 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))

View file

@ -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", %{

View file

@ -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