aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlain <lain@soykaf.club>2020-11-03 13:11:36 +0000
committerlain <lain@soykaf.club>2020-11-03 13:11:36 +0000
commitf7a3dcd3200bd6072d61ca51e91d5a2a75a9ffe7 (patch)
tree5e2e3767cce93218ae162bd564673d830f2d3e1b
parent0d8cc0905aeebb965df0cf755a171d21b01ed978 (diff)
parentc37118e6f26f0305d540047e4ccb8d594d2c0e6b (diff)
downloadpleroma-f7a3dcd3200bd6072d61ca51e91d5a2a75a9ffe7.tar.gz
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
-rw-r--r--CHANGELOG.md2
-rw-r--r--lib/pleroma/web/mastodon_api/views/conversation_view.ex14
-rw-r--r--test/pleroma/web/mastodon_api/controllers/conversation_controller_test.exs21
-rw-r--r--test/pleroma/web/mastodon_api/views/conversation_view_test.exs2
4 files changed, 36 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c4485b3db..2ee17d239 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -58,6 +58,8 @@ switched to a new configuration mechanism, however it was not officially removed
- Allow sending chat messages to yourself.
- 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.
+- 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)
diff --git a/lib/pleroma/web/mastodon_api/views/conversation_view.ex b/lib/pleroma/web/mastodon_api/views/conversation_view.ex
index a91994915..82fcff062 100644
--- a/lib/pleroma/web/mastodon_api/views/conversation_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/conversation_view.ex
@@ -33,8 +33,15 @@ defmodule Pleroma.Web.MastodonAPI.ConversationView do
end
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(),
@@ -43,7 +50,8 @@ defmodule Pleroma.Web.MastodonAPI.ConversationView do
last_status:
render(StatusView, "show.json",
activity: activity,
- direct_conversation_id: participation.id
+ direct_conversation_id: participation.id,
+ for: user
)
}
end
diff --git a/test/pleroma/web/mastodon_api/controllers/conversation_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/conversation_controller_test.exs
index b23b22752..c67e584dd 100644
--- a/test/pleroma/web/mastodon_api/controllers/conversation_controller_test.exs
+++ b/test/pleroma/web/mastodon_api/controllers/conversation_controller_test.exs
@@ -55,14 +55,35 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
account_ids = Enum.map(res_accounts, & &1["id"])
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 "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", %{
user: user_one,
user_two: user_two,
diff --git a/test/pleroma/web/mastodon_api/views/conversation_view_test.exs b/test/pleroma/web/mastodon_api/views/conversation_view_test.exs
index 2e8203c9b..20c10ba3d 100644
--- a/test/pleroma/web/mastodon_api/views/conversation_view_test.exs
+++ b/test/pleroma/web/mastodon_api/views/conversation_view_test.exs
@@ -36,9 +36,11 @@ defmodule Pleroma.Web.MastodonAPI.ConversationViewTest do
assert conversation.id == participation.id |> to_string()
assert conversation.last_status.id == activity.id
+ assert conversation.last_status.account.id == user.id
assert [account] = conversation.accounts
assert account.id == other_user.id
+
assert conversation.last_status.pleroma.direct_conversation_id == participation.id
end
end