Merge branch 'unify-follow' into 'develop'
Unify follow code with CommonAPI Closes #690 See merge request pleroma/pleroma!889
This commit is contained in:
commit
10248d86a2
@ -14,6 +14,19 @@ defmodule Pleroma.Web.CommonAPI do
|
|||||||
|
|
||||||
import Pleroma.Web.CommonAPI.Utils
|
import Pleroma.Web.CommonAPI.Utils
|
||||||
|
|
||||||
|
def follow(follower, followed) do
|
||||||
|
with {:ok, follower} <- User.maybe_direct_follow(follower, followed),
|
||||||
|
{:ok, activity} <- ActivityPub.follow(follower, followed),
|
||||||
|
{:ok, follower, followed} <-
|
||||||
|
User.wait_and_refresh(
|
||||||
|
Pleroma.Config.get([:activitypub, :follow_handshake_timeout]),
|
||||||
|
follower,
|
||||||
|
followed
|
||||||
|
) do
|
||||||
|
{:ok, follower, followed, activity}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def delete(activity_id, user) do
|
def delete(activity_id, user) do
|
||||||
with %Activity{data: %{"object" => %{"id" => object_id}}} <- Repo.get(Activity, activity_id),
|
with %Activity{data: %{"object" => %{"id" => object_id}}} <- Repo.get(Activity, activity_id),
|
||||||
%Object{} = object <- Object.normalize(object_id),
|
%Object{} = object <- Object.normalize(object_id),
|
||||||
|
@ -736,14 +736,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
|||||||
|
|
||||||
def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
|
def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
|
||||||
with %User{} = followed <- Repo.get(User, id),
|
with %User{} = followed <- Repo.get(User, id),
|
||||||
{:ok, follower} <- User.maybe_direct_follow(follower, followed),
|
{:ok, follower, followed, _} <- CommonAPI.follow(follower, followed) do
|
||||||
{:ok, _activity} <- ActivityPub.follow(follower, followed),
|
|
||||||
{:ok, follower, followed} <-
|
|
||||||
User.wait_and_refresh(
|
|
||||||
Config.get([:activitypub, :follow_handshake_timeout]),
|
|
||||||
follower,
|
|
||||||
followed
|
|
||||||
) do
|
|
||||||
conn
|
conn
|
||||||
|> put_view(AccountView)
|
|> put_view(AccountView)
|
||||||
|> render("relationship.json", %{user: follower, target: followed})
|
|> render("relationship.json", %{user: follower, target: followed})
|
||||||
@ -757,8 +750,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
|||||||
|
|
||||||
def follow(%{assigns: %{user: follower}} = conn, %{"uri" => uri}) do
|
def follow(%{assigns: %{user: follower}} = conn, %{"uri" => uri}) do
|
||||||
with %User{} = followed <- Repo.get_by(User, nickname: uri),
|
with %User{} = followed <- Repo.get_by(User, nickname: uri),
|
||||||
{:ok, follower} <- User.maybe_direct_follow(follower, followed),
|
{:ok, follower, followed, _} <- CommonAPI.follow(follower, followed) do
|
||||||
{:ok, _activity} <- ActivityPub.follow(follower, followed) do
|
|
||||||
conn
|
conn
|
||||||
|> put_view(AccountView)
|
|> put_view(AccountView)
|
||||||
|> render("account.json", %{user: followed, for: follower})
|
|> render("account.json", %{user: followed, for: follower})
|
||||||
|
@ -28,18 +28,8 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def follow(%User{} = follower, params) do
|
def follow(%User{} = follower, params) do
|
||||||
with {:ok, %User{} = followed} <- get_user(params),
|
with {:ok, %User{} = followed} <- get_user(params) do
|
||||||
{:ok, follower} <- User.maybe_direct_follow(follower, followed),
|
CommonAPI.follow(follower, followed)
|
||||||
{:ok, activity} <- ActivityPub.follow(follower, followed),
|
|
||||||
{:ok, follower, followed} <-
|
|
||||||
User.wait_and_refresh(
|
|
||||||
Pleroma.Config.get([:activitypub, :follow_handshake_timeout]),
|
|
||||||
follower,
|
|
||||||
followed
|
|
||||||
) do
|
|
||||||
{:ok, follower, followed, activity}
|
|
||||||
else
|
|
||||||
err -> err
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user