Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
c37118e6
Commit
c37118e6
authored
Nov 03, 2020
by
lain
Browse files
Conversations: A few refactors
parent
91f6c324
Changes
3
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/mastodon_api/views/conversation_view.ex
View file @
c37118e6
...
...
@@ -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
))
...
...
test/pleroma/web/mastodon_api/controllers/conversation_controller_test.exs
View file @
c37118e6
...
...
@@ -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"
,
%{
...
...
test/pleroma/web/mastodon_api/views/conversation_view_test.exs
View file @
c37118e6
...
...
@@ -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
a
ccount_ids
=
Enum
.
map
(
conversation
.
accounts
,
&
&1
.
id
)
assert
length
(
conversation
.
account
s
)
==
1
assert
other_user
.
id
in
account_ids
a
ssert
[
account
]
=
conversation
.
accounts
assert
account
.
id
==
other_user
.
id
assert
conversation
.
last_status
.
pleroma
.
direct_conversation_id
==
participation
.
id
end
end
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment