Add `with_muted` param to ChatController.index/2
authorEgor Kislitsyn <egor@kislitsyn.com>
Wed, 4 Nov 2020 12:40:12 +0000 (16:40 +0400)
committerEgor Kislitsyn <egor@kislitsyn.com>
Wed, 4 Nov 2020 12:40:12 +0000 (16:40 +0400)
docs/API/chats.md
lib/pleroma/web/api_spec/operations/chat_operation.ex
lib/pleroma/web/api_spec/operations/timeline_operation.ex
lib/pleroma/web/pleroma_api/controllers/chat_controller.ex
test/pleroma/web/pleroma_api/controllers/chat_controller_test.exs

index 9857aac672224e44aed52d73ea826d4eeded1561..f50144c865997a9d6971d6fe17767f1de34a251d 100644 (file)
@@ -116,6 +116,10 @@ The modified chat message
 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).
 
+Parameters:
+
+- with_muted: Include chats from muted users (boolean).
+
 Returned data:
 
 ```json
index 0dcfdb35467ef2e04f5493ef04546bb124bffd9b..560b81f1754eca8e4fbd2215d3c340955c323e7c 100644 (file)
@@ -6,6 +6,7 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do
   alias OpenApiSpex.Operation
   alias OpenApiSpex.Schema
   alias Pleroma.Web.ApiSpec.Schemas.ApiError
+  alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
   alias Pleroma.Web.ApiSpec.Schemas.Chat
   alias Pleroma.Web.ApiSpec.Schemas.ChatMessage
 
@@ -132,7 +133,10 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do
       tags: ["chat"],
       summary: "Get a list of chats that you participated in",
       operationId: "ChatController.index",
-      parameters: pagination_params(),
+      parameters: [
+        Operation.parameter(:with_muted, :query, BooleanLike, "Include chats from muted users")
+        | pagination_params()
+      ],
       responses: %{
         200 => Operation.response("The chats of the user", "application/json", chats_response())
       },
index 8e19bace7a9285a5a6b18814a0120b72529376be..1b5ad796fa08951b0fbf8e80e1fce253b886d30c 100644 (file)
@@ -159,7 +159,7 @@ defmodule Pleroma.Web.ApiSpec.TimelineOperation do
   end
 
   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
 
   defp exclude_visibilities_param do
index 8fc70c15a5ecafeeea9c9f051fb431cfed2dc525..77564b342c42268600c7c5c3757f5a68f1b7f2f7 100644 (file)
@@ -138,11 +138,10 @@ defmodule Pleroma.Web.PleromaAPI.ChatController do
     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 =
-      user
-      |> User.blocked_users_ap_ids()
-      |> Enum.concat(User.muted_users_ap_ids(user))
+      User.blocked_users_ap_ids(user) ++
+        if params[:with_muted], do: [], else: User.muted_users_ap_ids(user)
 
     chats =
       user_id
index b0498df2bd60ee6f2213e4cab441d4085b2ef474..c1e6a8cc5e18bddd931b3be6ca33535dd433fd88 100644 (file)
@@ -363,6 +363,13 @@ defmodule Pleroma.Web.PleromaAPI.ChatControllerTest do
         |> json_response_and_validate_schema(200)
 
       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
 
     test "it returns all chats", %{conn: conn, user: user} do