AccountController: Make setting accepts_chat_messages possible.
authorlain <lain@soykaf.club>
Fri, 3 Jul 2020 13:54:25 +0000 (15:54 +0200)
committerlain <lain@soykaf.club>
Fri, 3 Jul 2020 13:54:25 +0000 (15:54 +0200)
lib/pleroma/user.ex
lib/pleroma/web/api_spec/operations/account_operation.ex
lib/pleroma/web/mastodon_api/controllers/account_controller.ex
test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs

index a4130c89ff85146a8e1051cea507ab43d7d6d2b3..712bc30478c59c238804dda9450d4226e1c4e592 100644 (file)
@@ -483,7 +483,8 @@ defmodule Pleroma.User do
         :pleroma_settings_store,
         :discoverable,
         :actor_type,
-        :also_known_as
+        :also_known_as,
+        :accepts_chat_messages
       ]
     )
     |> unique_constraint(:nickname)
index 9bde8fc0dec593c45b676a0588e49afd074ce378..3c05fa55ff6a05bbf05ebca96962dae6faf37c05 100644 (file)
@@ -61,7 +61,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
       description: "Update the user's display and preferences.",
       operationId: "AccountController.update_credentials",
       security: [%{"oAuth" => ["write:accounts"]}],
-      requestBody: request_body("Parameters", update_creadentials_request(), required: true),
+      requestBody: request_body("Parameters", update_credentials_request(), required: true),
       responses: %{
         200 => Operation.response("Account", "application/json", Account),
         403 => Operation.response("Error", "application/json", ApiError)
@@ -458,7 +458,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
     }
   end
 
-  defp update_creadentials_request do
+  defp update_credentials_request do
     %Schema{
       title: "AccountUpdateCredentialsRequest",
       description: "POST body for creating an account",
@@ -492,6 +492,11 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
           nullable: true,
           description: "Whether manual approval of follow requests is required."
         },
+        accepts_chat_messages: %Schema{
+          allOf: [BooleanLike],
+          nullable: true,
+          description: "Whether the user accepts receiving chat messages."
+        },
         fields_attributes: %Schema{
           nullable: true,
           oneOf: [
index b5008d69b261daca246932809629bf0fe5bf821c..7ff767db6dc86836d0ff7a93276731ab2175c996 100644 (file)
@@ -160,7 +160,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
         :show_role,
         :skip_thread_containment,
         :allow_following_move,
-        :discoverable
+        :discoverable,
+        :accepts_chat_messages
       ]
       |> Enum.reduce(%{}, fn key, acc ->
         Maps.put_if_present(acc, key, params[key], &{:ok, truthy_param?(&1)})
index f67d294ba2239ed81441044f9449e02335e6f3ef..37e33bc3381e11ae4426be7bda634aaaa2d13cd3 100644 (file)
@@ -108,6 +108,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
       assert user_data["locked"] == true
     end
 
+    test "updates the user's chat acceptance status", %{conn: conn} do
+      conn = patch(conn, "/api/v1/accounts/update_credentials", %{accepts_chat_messages: "false"})
+
+      assert user_data = json_response_and_validate_schema(conn, 200)
+      assert user_data["pleroma"]["accepts_chat_messages"] == false
+    end
+
     test "updates the user's allow_following_move", %{user: user, conn: conn} do
       assert user.allow_following_move == true