CommonAPI: Switch to pipeline for following.
authorlain <lain@soykaf.club>
Wed, 8 Jul 2020 13:40:56 +0000 (15:40 +0200)
committerlain <lain@soykaf.club>
Wed, 8 Jul 2020 13:40:56 +0000 (15:40 +0200)
lib/pleroma/web/activity_pub/side_effects.ex
lib/pleroma/web/common_api/common_api.ex
test/web/mastodon_api/mastodon_api_test.exs
test/web/mastodon_api/views/account_view_test.exs

index 2845609138a86fba5c9cbcc219e6d2057496621c..de02baf0f8db15e3bfa8a024755ec388e846dc66 100644 (file)
@@ -44,6 +44,8 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
       if followed.local && !followed.locked do
         Utils.update_follow_state_for_all(object, "accept")
         FollowingRelationship.update(follower, followed, :follow_accept)
+        User.update_follower_count(followed)
+        User.update_following_count(follower)
 
         %{
           to: [following_user],
@@ -78,7 +80,9 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
       meta
       |> add_notifications(notifications)
 
-    {:ok, object, meta}
+    updated_object = Activity.get_by_ap_id(follow_id)
+
+    {:ok, updated_object, meta}
   end
 
   # Tasks this handles:
index fd714907953901aaf3f2dd814e0347909c9d4f76..4d5b0decf77c3a3b3aec03b9a1f046a81de35ed9 100644 (file)
@@ -101,10 +101,14 @@ defmodule Pleroma.Web.CommonAPI do
   def follow(follower, followed) do
     timeout = Pleroma.Config.get([:activitypub, :follow_handshake_timeout])
 
-    with {:ok, follower} <- User.maybe_direct_follow(follower, followed),
-         {:ok, activity} <- ActivityPub.follow(follower, followed),
+    with {:ok, follow_data, _} <- Builder.follow(follower, followed),
+         {:ok, activity, _} <- Pipeline.common_pipeline(follow_data, local: true),
          {:ok, follower, followed} <- User.wait_and_refresh(timeout, follower, followed) do
-      {:ok, follower, followed, activity}
+      if activity.data["state"] == "reject" do
+        {:error, :rejected}
+      else
+        {:ok, follower, followed, activity}
+      end
     end
   end
 
index a7f9c5205f125ed418fb91b1dcf2ab6f3896b1ba..c08be37d4ae62c094f1963d1c1e8df83fdc69d63 100644 (file)
@@ -18,7 +18,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
       follower = insert(:user)
       user = insert(:user, local: true, deactivated: true)
       {:error, error} = MastodonAPI.follow(follower, user)
-      assert error == "Could not follow user: #{user.nickname} is deactivated."
+      assert error == :rejected
     end
 
     test "following for user" do
index 80b1f734c041da92081c3f120fac8ab0911a5ef3..3e2e780e3067682e08e43e75c48e2a9472769ae0 100644 (file)
@@ -372,6 +372,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
       user = insert(:user, hide_followers: true, hide_follows: true)
       other_user = insert(:user)
       {:ok, user, other_user, _activity} = CommonAPI.follow(user, other_user)
+
+      assert User.following?(user, other_user)
+      assert Pleroma.FollowingRelationship.follower_count(other_user) == 1
       {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
 
       assert %{