Add with_muted
param to ChatController.index/2
This commit is contained in:
parent
be52819a11
commit
ca95cbe0b4
5 changed files with 20 additions and 6 deletions
|
@ -116,6 +116,10 @@ The modified chat message
|
||||||
This will return a list of chats that you have been involved in, sorted by their
|
This will return a list of chats that you have been involved in, sorted by their
|
||||||
last update (so new chats will be at the top).
|
last update (so new chats will be at the top).
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
|
||||||
|
- with_muted: Include chats from muted users (boolean).
|
||||||
|
|
||||||
Returned data:
|
Returned data:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
|
|
|
@ -6,6 +6,7 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do
|
||||||
alias OpenApiSpex.Operation
|
alias OpenApiSpex.Operation
|
||||||
alias OpenApiSpex.Schema
|
alias OpenApiSpex.Schema
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.ApiError
|
alias Pleroma.Web.ApiSpec.Schemas.ApiError
|
||||||
|
alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.Chat
|
alias Pleroma.Web.ApiSpec.Schemas.Chat
|
||||||
alias Pleroma.Web.ApiSpec.Schemas.ChatMessage
|
alias Pleroma.Web.ApiSpec.Schemas.ChatMessage
|
||||||
|
|
||||||
|
@ -132,7 +133,10 @@ def index_operation do
|
||||||
tags: ["chat"],
|
tags: ["chat"],
|
||||||
summary: "Get a list of chats that you participated in",
|
summary: "Get a list of chats that you participated in",
|
||||||
operationId: "ChatController.index",
|
operationId: "ChatController.index",
|
||||||
parameters: pagination_params(),
|
parameters: [
|
||||||
|
Operation.parameter(:with_muted, :query, BooleanLike, "Include chats from muted users")
|
||||||
|
| pagination_params()
|
||||||
|
],
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => Operation.response("The chats of the user", "application/json", chats_response())
|
200 => Operation.response("The chats of the user", "application/json", chats_response())
|
||||||
},
|
},
|
||||||
|
|
|
@ -159,7 +159,7 @@ defp local_param do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp with_muted_param do
|
defp with_muted_param do
|
||||||
Operation.parameter(:with_muted, :query, BooleanLike, "Includeactivities by muted users")
|
Operation.parameter(:with_muted, :query, BooleanLike, "Include activities by muted users")
|
||||||
end
|
end
|
||||||
|
|
||||||
defp exclude_visibilities_param do
|
defp exclude_visibilities_param do
|
||||||
|
|
|
@ -138,11 +138,10 @@ def messages(%{assigns: %{user: user}} = conn, %{id: id} = params) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def index(%{assigns: %{user: %{id: user_id} = user}} = conn, _params) do
|
def index(%{assigns: %{user: %{id: user_id} = user}} = conn, params) do
|
||||||
exclude_users =
|
exclude_users =
|
||||||
user
|
User.blocked_users_ap_ids(user) ++
|
||||||
|> User.blocked_users_ap_ids()
|
if params[:with_muted], do: [], else: User.muted_users_ap_ids(user)
|
||||||
|> Enum.concat(User.muted_users_ap_ids(user))
|
|
||||||
|
|
||||||
chats =
|
chats =
|
||||||
user_id
|
user_id
|
||||||
|
|
|
@ -363,6 +363,13 @@ test "it does not return chats with users you muted", %{conn: conn, user: user}
|
||||||
|> json_response_and_validate_schema(200)
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
assert length(result) == 0
|
assert length(result) == 0
|
||||||
|
|
||||||
|
result =
|
||||||
|
conn
|
||||||
|
|> get("/api/v1/pleroma/chats?with_muted=true")
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
|
assert length(result) == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it returns all chats", %{conn: conn, user: user} do
|
test "it returns all chats", %{conn: conn, user: user} do
|
||||||
|
|
Loading…
Reference in a new issue