forked from AkkomaGang/akkoma
ActivityPub: Remove reject
, move everything to the Pipeline.
This commit is contained in:
parent
7224bf309e
commit
2e347e8286
3 changed files with 7 additions and 46 deletions
|
@ -285,27 +285,6 @@ def listen(%{to: to, actor: actor, context: context, object: object} = params) d
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec reject(map()) :: {:ok, Activity.t()} | {:error, any()}
|
|
||||||
def reject(params) do
|
|
||||||
accept_or_reject("Reject", params)
|
|
||||||
end
|
|
||||||
|
|
||||||
@spec accept_or_reject(String.t(), map()) :: {:ok, Activity.t()} | {:error, any()}
|
|
||||||
defp accept_or_reject(type, %{to: to, actor: actor, object: object} = params) do
|
|
||||||
local = Map.get(params, :local, true)
|
|
||||||
activity_id = Map.get(params, :activity_id, nil)
|
|
||||||
|
|
||||||
data =
|
|
||||||
%{"to" => to, "type" => type, "actor" => actor.ap_id, "object" => object}
|
|
||||||
|> Maps.put_if_present("id", activity_id)
|
|
||||||
|
|
||||||
with {:ok, activity} <- insert(data, local),
|
|
||||||
_ <- notify_and_stream(activity),
|
|
||||||
:ok <- maybe_federate(activity) do
|
|
||||||
{:ok, activity}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
@spec unfollow(User.t(), User.t(), String.t() | nil, boolean()) ::
|
@spec unfollow(User.t(), User.t(), String.t() | nil, boolean()) ::
|
||||||
{:ok, Activity.t()} | nil | {:error, any()}
|
{:ok, Activity.t()} | nil | {:error, any()}
|
||||||
def unfollow(follower, followed, activity_id \\ nil, local \\ true) do
|
def unfollow(follower, followed, activity_id \\ nil, local \\ true) do
|
||||||
|
|
|
@ -55,6 +55,7 @@ def handle(
|
||||||
# Task this handles
|
# Task this handles
|
||||||
# - Rejects all existing follow activities for this person
|
# - Rejects all existing follow activities for this person
|
||||||
# - Updates the follow state
|
# - Updates the follow state
|
||||||
|
# - Dismisses notificatios
|
||||||
def handle(
|
def handle(
|
||||||
%{
|
%{
|
||||||
data: %{
|
data: %{
|
||||||
|
@ -71,6 +72,7 @@ def handle(
|
||||||
%User{} = follower <- User.get_cached_by_ap_id(follower_id),
|
%User{} = follower <- User.get_cached_by_ap_id(follower_id),
|
||||||
{:ok, _follow_activity} <- Utils.update_follow_state_for_all(follow_activity, "reject") do
|
{:ok, _follow_activity} <- Utils.update_follow_state_for_all(follow_activity, "reject") do
|
||||||
FollowingRelationship.update(follower, followed, :follow_reject)
|
FollowingRelationship.update(follower, followed, :follow_reject)
|
||||||
|
Notification.dismiss(follow_activity)
|
||||||
end
|
end
|
||||||
|
|
||||||
{:ok, object, meta}
|
{:ok, object, meta}
|
||||||
|
@ -100,19 +102,9 @@ def handle(
|
||||||
{:ok, _activity, _} = Pipeline.common_pipeline(accept_data, local: true)
|
{:ok, _activity, _} = Pipeline.common_pipeline(accept_data, local: true)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
{:following, {:error, _}, follower, followed} ->
|
{:following, {:error, _}, _follower, followed} ->
|
||||||
Utils.update_follow_state_for_all(object, "reject")
|
{:ok, reject_data, _} = Builder.reject(followed, object)
|
||||||
FollowingRelationship.update(follower, followed, :follow_reject)
|
{:ok, _activity, _} = Pipeline.common_pipeline(reject_data, local: true)
|
||||||
|
|
||||||
if followed.local do
|
|
||||||
%{
|
|
||||||
to: [follower.ap_id],
|
|
||||||
actor: followed,
|
|
||||||
object: follow_id,
|
|
||||||
local: true
|
|
||||||
}
|
|
||||||
|> ActivityPub.reject()
|
|
||||||
end
|
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
nil
|
nil
|
||||||
|
|
|
@ -6,9 +6,7 @@ defmodule Pleroma.Web.CommonAPI do
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.ActivityExpiration
|
alias Pleroma.ActivityExpiration
|
||||||
alias Pleroma.Conversation.Participation
|
alias Pleroma.Conversation.Participation
|
||||||
alias Pleroma.FollowingRelationship
|
|
||||||
alias Pleroma.Formatter
|
alias Pleroma.Formatter
|
||||||
alias Pleroma.Notification
|
|
||||||
alias Pleroma.Object
|
alias Pleroma.Object
|
||||||
alias Pleroma.ThreadMute
|
alias Pleroma.ThreadMute
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
@ -130,16 +128,8 @@ def accept_follow_request(follower, followed) do
|
||||||
|
|
||||||
def reject_follow_request(follower, followed) do
|
def reject_follow_request(follower, followed) do
|
||||||
with %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed),
|
with %Activity{} = follow_activity <- Utils.fetch_latest_follow(follower, followed),
|
||||||
{:ok, follow_activity} <- Utils.update_follow_state_for_all(follow_activity, "reject"),
|
{:ok, reject_data, _} <- Builder.reject(followed, follow_activity),
|
||||||
{:ok, _relationship} <- FollowingRelationship.update(follower, followed, :follow_reject),
|
{:ok, _activity, _} <- Pipeline.common_pipeline(reject_data, local: true) do
|
||||||
{:ok, _notifications} <- Notification.dismiss(follow_activity),
|
|
||||||
{:ok, _activity} <-
|
|
||||||
ActivityPub.reject(%{
|
|
||||||
to: [follower.ap_id],
|
|
||||||
actor: followed,
|
|
||||||
object: follow_activity.data["id"],
|
|
||||||
type: "Reject"
|
|
||||||
}) do
|
|
||||||
{:ok, follower}
|
{:ok, follower}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue