Add 'notifying' to relationship for compatibility with Mastodon
authormarcin mikołajczak <git@mkljczk.pl>
Mon, 6 Dec 2021 20:23:34 +0000 (21:23 +0100)
committermarcin mikołajczak <git@mkljczk.pl>
Mon, 6 Dec 2021 20:24:12 +0000 (21:24 +0100)
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
docs/development/API/pleroma_api.md
lib/pleroma/web/api_spec/operations/account_operation.ex
lib/pleroma/web/api_spec/schemas/account.ex
lib/pleroma/web/api_spec/schemas/account_relationship.ex
lib/pleroma/web/api_spec/schemas/status.ex
lib/pleroma/web/mastodon_api/mastodon_api.ex
lib/pleroma/web/mastodon_api/views/account_view.ex
test/pleroma/web/mastodon_api/controllers/account_controller_test.exs
test/pleroma/web/mastodon_api/views/account_view_test.exs

index 8f6422da04bef9d546b3e5f15bb1064b9f62368b..74a1ad206347c1b2c9bffd0fe1cc955beba73047 100644 (file)
@@ -159,6 +159,7 @@ See [Admin-API](admin_api.md)
   "muting": false,
   "muting_notifications": false,
   "subscribing": true,
+  "notifying": true,
   "requested": false,
   "domain_blocking": false,
   "showing_reblogs": true,
@@ -183,6 +184,7 @@ See [Admin-API](admin_api.md)
   "muting": false,
   "muting_notifications": false,
   "subscribing": false,
+  "notifying": false,
   "requested": false,
   "domain_blocking": false,
   "showing_reblogs": true,
index cb978c775bfeb9c008168277ffc24bc65aa7b64b..4fe5a3c033b94938423c842ddf3399f3dbb0d4a8 100644 (file)
@@ -694,6 +694,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
           "requested" => false,
           "domain_blocking" => false,
           "subscribing" => false,
+          "notifying" => false,
           "endorsed" => true
         },
         %{
@@ -708,6 +709,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
           "requested" => true,
           "domain_blocking" => false,
           "subscribing" => false,
+          "notifying" => false,
           "endorsed" => false
         },
         %{
@@ -722,6 +724,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
           "requested" => false,
           "domain_blocking" => true,
           "subscribing" => true,
+          "notifying" => true,
           "endorsed" => false
         }
       ]
index bd7143ab959420bb00e9b2ab2264cf3777f27fa1..ad1a855441374cd5587757c93dd85372faf40d8b 100644 (file)
@@ -196,7 +196,8 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
           "muting_notifications" => false,
           "requested" => false,
           "showing_reblogs" => true,
-          "subscribing" => false
+          "subscribing" => false,
+          "notifying" => false
         },
         "settings_store" => %{
           "pleroma-fe" => %{}
index 16b73ebb4191e02d32be50bcbc8e34b7ba13a6ee..b4f6d25b091de440d132e7d5548f2c8769574a68 100644 (file)
@@ -24,7 +24,8 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountRelationship do
       muting_notifications: %Schema{type: :boolean},
       requested: %Schema{type: :boolean},
       showing_reblogs: %Schema{type: :boolean},
-      subscribing: %Schema{type: :boolean}
+      subscribing: %Schema{type: :boolean},
+      notifying: %Schema{type: :boolean}
     },
     example: %{
       "blocked_by" => false,
@@ -38,7 +39,8 @@ defmodule Pleroma.Web.ApiSpec.Schemas.AccountRelationship do
       "muting_notifications" => false,
       "requested" => false,
       "showing_reblogs" => true,
-      "subscribing" => false
+      "subscribing" => false,
+      "notifying" => false
     }
   })
 end
index 3d042dc19a225f2d4e268a97695241f9a1c2840d..0bf3312d1c9f6b663c0c5738e5e63bfa84eeb415 100644 (file)
@@ -284,7 +284,8 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do
             "muting_notifications" => false,
             "requested" => false,
             "showing_reblogs" => true,
-            "subscribing" => false
+            "subscribing" => false,
+            "notifying" => false
           },
           "skip_thread_containment" => false,
           "tags" => []
index fb713d47c90fa65c067968d761fe9f5a8907f654..23846b36a0a3101784b2e27358b5de14407c26c3 100644 (file)
@@ -41,10 +41,12 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPI do
     User.subscribe(follower, followed)
   end
 
-  defp set_subscription(_, {:ok, follower, followed, _}) do
+  defp set_subscription(false, {:ok, follower, followed, _}) do
     User.unsubscribe(follower, followed)
   end
 
+  defp set_subscription(_, _), do: {:ok, nil}
+
   @spec get_followers(User.t(), map()) :: list(User.t())
   def get_followers(user, params \\ %{}) do
     user
index 9e9de33f6167c615158440da34d0f6b3dd877a98..25752cf5634dcd9476a069721aced7b2ef7627bd 100644 (file)
@@ -101,6 +101,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
         User.following?(target, reading_user)
       end
 
+    subscribing =
+      UserRelationship.exists?(
+        user_relationships,
+        :inverse_subscription,
+        target,
+        reading_user,
+        &User.subscribed_to?(&2, &1)
+      )
+
     # NOTE: adjust UserRelationship.view_relationships_option/2 on new relation-related flags
     %{
       id: to_string(target.id),
@@ -138,14 +147,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
           target,
           &User.muted_notifications?(&1, &2)
         ),
-      subscribing:
-        UserRelationship.exists?(
-          user_relationships,
-          :inverse_subscription,
-          target,
-          reading_user,
-          &User.subscribed_to?(&2, &1)
-        ),
+      subscribing: subscribing,
+      notifying: subscribing,
       requested: follow_state == :follow_pending,
       domain_blocking: User.blocks_domain?(reading_user, target),
       showing_reblogs:
index 70c6b152ef743feb8c1303bf15468a0ad32e694b..581944b8a1b5aceaff68a2198de31767f90685b6 100644 (file)
@@ -922,7 +922,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
                |> json_response_and_validate_schema(200)
     end
 
-    test "following with subscription and unsubscribing when notify is nil" do
+    test "following with subscription and unsubscribing" do
       %{conn: conn} = oauth_access(["follow"])
       followed = insert(:user)
 
@@ -937,7 +937,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
       ret_conn =
         conn
         |> put_req_header("content-type", "application/json")
-        |> post("/api/v1/accounts/#{followed.id}/follow")
+        |> post("/api/v1/accounts/#{followed.id}/follow", %{notify: false})
 
       assert %{"id" => _id, "subscribing" => false} =
                json_response_and_validate_schema(ret_conn, 200)
index 60881756d9b402a3d624f44b17d6239c66d10994..aeddd6b4cbbb81cac8af7f77950948febd155887 100644 (file)
@@ -268,6 +268,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
       muting: false,
       muting_notifications: false,
       subscribing: false,
+      notifying: false,
       requested: false,
       domain_blocking: false,
       showing_reblogs: true,
@@ -293,6 +294,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
             muting: true,
             muting_notifications: true,
             subscribing: true,
+            notifying: true,
             showing_reblogs: false,
             id: to_string(other_user.id)
           }