Unfollow should also unsubscribe
authorSergey Suprunenko <suprunenko.s@gmail.com>
Sun, 14 Jul 2019 19:25:03 +0000 (19:25 +0000)
committerkaniini <ariadne@dereferenced.org>
Sun, 14 Jul 2019 19:25:03 +0000 (19:25 +0000)
CHANGELOG.md
lib/pleroma/web/common_api/common_api.ex
test/web/common_api/common_api_test.exs

index e7d7e0ef5bf796976b6426337b51e44e447fc36c..7fc8db31cbc6f9d8978bb262f2c85f171a60243c 100644 (file)
@@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 - Configuration: Filter.AnonymizeFilename added ability to retain file extension with custom text
 - Federation: Return 403 errors when trying to request pages from a user's follower/following collections if they have `hide_followers`/`hide_follows` set
 - NodeInfo: Return `skipThreadContainment` in `metadata` for the `skip_thread_containment` option
+- Mastodon API: Unsubscribe followers when they unfollow a user
 
 ### Fixed
 - Not being able to pin unlisted posts
index f1450b1139178d940a78f854232613b67980ca9c..949baa3b036098ad701f2781e9f02c21f8e10403 100644 (file)
@@ -31,7 +31,8 @@ defmodule Pleroma.Web.CommonAPI do
 
   def unfollow(follower, unfollowed) do
     with {:ok, follower, _follow_activity} <- User.unfollow(follower, unfollowed),
-         {:ok, _activity} <- ActivityPub.unfollow(follower, unfollowed) do
+         {:ok, _activity} <- ActivityPub.unfollow(follower, unfollowed),
+         {:ok, _unfollowed} <- User.unsubscribe(follower, unfollowed) do
       {:ok, follower}
     end
   end
index 958c931c49a21353d6cdf5f9ac8a286ec1f3c1e0..b59b6cbf659be3478e5dc7718af28e451a183dfd 100644 (file)
@@ -346,6 +346,20 @@ defmodule Pleroma.Web.CommonAPITest do
     end
   end
 
+  describe "unfollow/2" do
+    test "also unsubscribes a user" do
+      [follower, followed] = insert_pair(:user)
+      {:ok, follower, followed, _} = CommonAPI.follow(follower, followed)
+      {:ok, followed} = User.subscribe(follower, followed)
+
+      assert User.subscribed_to?(follower, followed)
+
+      {:ok, follower} = CommonAPI.unfollow(follower, followed)
+
+      refute User.subscribed_to?(follower, followed)
+    end
+  end
+
   describe "accept_follow_request/2" do
     test "after acceptance, it sets all existing pending follow request states to 'accept'" do
       user = insert(:user, info: %{locked: true})