update the follower count when a follower is blocked
authorSachin Joshi <satchin.joshi@gmail.com>
Mon, 8 Apr 2019 09:31:18 +0000 (15:16 +0545)
committerSachin Joshi <satchin.joshi@gmail.com>
Tue, 9 Apr 2019 03:30:45 +0000 (09:15 +0545)
lib/pleroma/user.ex
test/user_test.exs

index 5012aef77aa543be08d076e2db3be6a278a51e93..a6e2c8b9745613f35676d49dd89e8f5d76856994 100644 (file)
@@ -937,6 +937,8 @@ defmodule Pleroma.User do
       unfollow(blocked, blocker)
     end
 
+    {:ok, blocker} = update_follower_count(blocker)
+
     info_cng =
       blocker.info
       |> User.Info.add_to_block(ap_id)
index 38712cebb6aafb1edf7f4639806b4a52a5a87d97..4f98af683d96f57e019afe9d51bd9be43be5497e 100644 (file)
@@ -1125,4 +1125,21 @@ defmodule Pleroma.UserTest do
     assert {:ok, user_state3} = User.bookmark(user, id2)
     assert user_state3.bookmarks == [id2]
   end
+
+  test "follower count is updated when a follower is blocked" do
+    user = insert(:user)
+    follower = insert(:user)
+    follower2 = insert(:user)
+    follower3 = insert(:user)
+
+    {:ok, follower} = Pleroma.User.follow(follower, user)
+    {:ok, _follower2} = Pleroma.User.follow(follower2, user)
+    {:ok, _follower3} = Pleroma.User.follow(follower3, user)
+
+    {:ok, _} = Pleroma.User.block(user, follower)
+
+    user_show = Pleroma.Web.TwitterAPI.UserView.render("show.json", %{user: user})
+
+    assert Map.get(user_show, "followers_count") == 2
+  end
 end