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
be52819a
Verified
Commit
be52819a
authored
Nov 02, 2020
by
minibikini
Browse files
Hide chats from muted users
parent
9fbe9ef7
Pipeline
#32489
passed with stages
in 17 minutes and 39 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/pleroma_api/controllers/chat_controller.ex
View file @
be52819a
...
...
@@ -15,7 +15,6 @@ defmodule Pleroma.Web.PleromaAPI.ChatController do
alias
Pleroma
.
User
alias
Pleroma
.
Web
.
CommonAPI
alias
Pleroma
.
Web
.
PleromaAPI
.
Chat
.
MessageReferenceView
alias
Pleroma
.
Web
.
PleromaAPI
.
ChatView
alias
Pleroma
.
Web
.
Plugs
.
OAuthScopesPlug
import
Ecto
.
Query
...
...
@@ -121,9 +120,7 @@ def mark_as_read(
)
do
with
{
:ok
,
chat
}
<-
Chat
.
get_by_user_and_id
(
user
,
id
),
{
_n
,
_
}
<-
MessageReference
.
set_all_seen_for_chat
(
chat
,
last_read_id
)
do
conn
|>
put_view
(
ChatView
)
|>
render
(
"show.json"
,
chat:
chat
)
render
(
conn
,
"show.json"
,
chat:
chat
)
end
end
...
...
@@ -142,32 +139,30 @@ def messages(%{assigns: %{user: user}} = conn, %{id: id} = params) do
end
def
index
(%{
assigns:
%{
user:
%{
id:
user_id
}
=
user
}}
=
conn
,
_params
)
do
blocked_ap_ids
=
User
.
blocked_users_ap_ids
(
user
)
exclude_users
=
user
|>
User
.
blocked_users_ap_ids
()
|>
Enum
.
concat
(
User
.
muted_users_ap_ids
(
user
))
chats
=
Chat
.
for_user_query
(
user_id
)
|>
where
([
c
],
c
.
recipient
not
in
^
blocked_ap_ids
)
user_id
|>
Chat
.
for_user_query
()
|>
where
([
c
],
c
.
recipient
not
in
^
exclude_users
)
|>
Repo
.
all
()
conn
|>
put_view
(
ChatView
)
|>
render
(
"index.json"
,
chats:
chats
)
render
(
conn
,
"index.json"
,
chats:
chats
)
end
def
create
(%{
assigns:
%{
user:
user
}}
=
conn
,
%{
id:
id
})
do
with
%
User
{
ap_id:
recipient
}
<-
User
.
get_cached_by_id
(
id
),
{
:ok
,
%
Chat
{}
=
chat
}
<-
Chat
.
get_or_create
(
user
.
id
,
recipient
)
do
conn
|>
put_view
(
ChatView
)
|>
render
(
"show.json"
,
chat:
chat
)
render
(
conn
,
"show.json"
,
chat:
chat
)
end
end
def
show
(%{
assigns:
%{
user:
user
}}
=
conn
,
%{
id:
id
})
do
with
{
:ok
,
chat
}
<-
Chat
.
get_by_user_and_id
(
user
,
id
)
do
conn
|>
put_view
(
ChatView
)
|>
render
(
"show.json"
,
chat:
chat
)
render
(
conn
,
"show.json"
,
chat:
chat
)
end
end
...
...
test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs
View file @
be52819a
...
...
@@ -343,6 +343,28 @@ test "it does not return chats with users you blocked", %{conn: conn, user: user
assert
length
(
result
)
==
0
end
test
"it does not return chats with users you muted"
,
%{
conn:
conn
,
user:
user
}
do
recipient
=
insert
(
:user
)
{
:ok
,
_
}
=
Chat
.
get_or_create
(
user
.
id
,
recipient
.
ap_id
)
result
=
conn
|>
get
(
"/api/v1/pleroma/chats"
)
|>
json_response_and_validate_schema
(
200
)
assert
length
(
result
)
==
1
User
.
mute
(
user
,
recipient
)
result
=
conn
|>
get
(
"/api/v1/pleroma/chats"
)
|>
json_response_and_validate_schema
(
200
)
assert
length
(
result
)
==
0
end
test
"it returns all chats"
,
%{
conn:
conn
,
user:
user
}
do
Enum
.
each
(
1
..
30
,
fn
_
->
recipient
=
insert
(
:user
)
...
...
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