Merge branch 'patch-4' into 'develop'

ConversationView: add current user to conversations, according to Mastodon behaviour, fix last_status.account being not filled

Closes #2217

See merge request pleroma/pleroma!3089
This commit is contained in:
lain 2020-11-03 13:11:36 +00:00
commit f7a3dcd320
4 changed files with 36 additions and 3 deletions

View File

@ -58,6 +58,8 @@ switched to a new configuration mechanism, however it was not officially removed
- Allow sending chat messages to yourself. - Allow sending chat messages to yourself.
- Fix remote users with a whitespace name. - Fix remote users with a whitespace name.
- OStatus / static FE endpoints: fixed inaccessibility for anonymous users on non-federating instances, switched to handling per `:restrict_unauthenticated` setting. - OStatus / static FE endpoints: fixed inaccessibility for anonymous users on non-federating instances, switched to handling per `:restrict_unauthenticated` setting.
- Mastodon API: Current user is now included in conversation if it's the only participant
- Mastodon API: Fixed last_status.account being not filled with account data
## Unreleased (Patch) ## Unreleased (Patch)

View File

@ -33,8 +33,15 @@ def render("participation.json", %{participation: participation, for: user}) do
end end
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 the current user.
users = Enum.reject(participation.recipients, &(&1.id == user.id)) # 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))
else
participation.recipients
end
%{ %{
id: participation.id |> to_string(), id: participation.id |> to_string(),
@ -43,7 +50,8 @@ def render("participation.json", %{participation: participation, for: user}) do
last_status: last_status:
render(StatusView, "show.json", render(StatusView, "show.json",
activity: activity, activity: activity,
direct_conversation_id: participation.id direct_conversation_id: participation.id,
for: user
) )
} }
end end

View File

@ -55,14 +55,35 @@ test "returns correct conversations", %{
account_ids = Enum.map(res_accounts, & &1["id"]) account_ids = Enum.map(res_accounts, & &1["id"])
assert length(res_accounts) == 2 assert length(res_accounts) == 2
assert user_one.id not in account_ids
assert user_two.id in account_ids assert user_two.id in account_ids
assert user_three.id in account_ids assert user_three.id in account_ids
assert is_binary(res_id) assert is_binary(res_id)
assert unread == false assert unread == false
assert res_last_status["id"] == direct.id assert res_last_status["id"] == direct.id
assert res_last_status["account"]["id"] == user_one.id
assert Participation.unread_count(user_one) == 0 assert Participation.unread_count(user_one) == 0
end end
test "includes the user if the user is the only participant", %{
user: user_one,
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" => [account]
}
] = response
assert user_one.id == account["id"]
end
test "observes limit params", %{ test "observes limit params", %{
user: user_one, user: user_one,
user_two: user_two, user_two: user_two,

View File

@ -36,9 +36,11 @@ test "represents a Mastodon Conversation entity" do
assert conversation.id == participation.id |> to_string() assert conversation.id == participation.id |> to_string()
assert conversation.last_status.id == activity.id assert conversation.last_status.id == activity.id
assert conversation.last_status.account.id == user.id
assert [account] = conversation.accounts assert [account] = conversation.accounts
assert account.id == other_user.id assert account.id == other_user.id
assert conversation.last_status.pleroma.direct_conversation_id == participation.id assert conversation.last_status.pleroma.direct_conversation_id == participation.id
end end
end end