CommonAPI: Switch to pipeline for following.

This commit is contained in:
lain 2020-07-08 15:40:56 +02:00
parent 172f4aff8e
commit 9dda8b5427
4 changed files with 16 additions and 5 deletions

View File

@ -44,6 +44,8 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
if followed.local && !followed.locked do if followed.local && !followed.locked do
Utils.update_follow_state_for_all(object, "accept") Utils.update_follow_state_for_all(object, "accept")
FollowingRelationship.update(follower, followed, :follow_accept) FollowingRelationship.update(follower, followed, :follow_accept)
User.update_follower_count(followed)
User.update_following_count(follower)
%{ %{
to: [following_user], to: [following_user],
@ -78,7 +80,9 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
meta meta
|> add_notifications(notifications) |> add_notifications(notifications)
{:ok, object, meta} updated_object = Activity.get_by_ap_id(follow_id)
{:ok, updated_object, meta}
end end
# Tasks this handles: # Tasks this handles:

View File

@ -101,12 +101,16 @@ defmodule Pleroma.Web.CommonAPI do
def follow(follower, followed) do def follow(follower, followed) do
timeout = Pleroma.Config.get([:activitypub, :follow_handshake_timeout]) timeout = Pleroma.Config.get([:activitypub, :follow_handshake_timeout])
with {:ok, follower} <- User.maybe_direct_follow(follower, followed), with {:ok, follow_data, _} <- Builder.follow(follower, followed),
{:ok, activity} <- ActivityPub.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} <- User.wait_and_refresh(timeout, follower, followed) do
if activity.data["state"] == "reject" do
{:error, :rejected}
else
{:ok, follower, followed, activity} {:ok, follower, followed, activity}
end end
end end
end
def unfollow(follower, unfollowed) do def unfollow(follower, unfollowed) do
with {:ok, follower, _follow_activity} <- User.unfollow(follower, unfollowed), with {:ok, follower, _follow_activity} <- User.unfollow(follower, unfollowed),

View File

@ -18,7 +18,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPITest do
follower = insert(:user) follower = insert(:user)
user = insert(:user, local: true, deactivated: true) user = insert(:user, local: true, deactivated: true)
{:error, error} = MastodonAPI.follow(follower, user) {:error, error} = MastodonAPI.follow(follower, user)
assert error == "Could not follow user: #{user.nickname} is deactivated." assert error == :rejected
end end
test "following for user" do test "following for user" do

View File

@ -372,6 +372,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
user = insert(:user, hide_followers: true, hide_follows: true) user = insert(:user, hide_followers: true, hide_follows: true)
other_user = insert(:user) other_user = insert(:user)
{:ok, user, other_user, _activity} = CommonAPI.follow(user, other_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) {:ok, _other_user, user, _activity} = CommonAPI.follow(other_user, user)
assert %{ assert %{