don't persist undo of follows #149

Merged
floatingghost merged 5 commits from follow-undo-persistance into develop 2022-08-05 13:28:56 +00:00
2 changed files with 62 additions and 1 deletions
Showing only changes of commit f8acef27c4 - Show all commits

View file

@ -327,7 +327,9 @@ def unfollow(follower, followed, activity_id \\ nil, local \\ true) do
end
end
defp do_unfollow(follower, followed, activity_id, local) do
defp do_unfollow(follower, followed, activity_id, local)
defp do_unfollow(follower, followed, activity_id, local) when local == true do
with %Activity{} = follow_activity <- fetch_latest_follow(follower, followed),
{:ok, follow_activity} <- update_follow_state(follow_activity, "cancelled"),
unfollow_data <- make_unfollow_data(follower, followed, follow_activity, activity_id),
@ -341,6 +343,32 @@ defp do_unfollow(follower, followed, activity_id, local) do
end
end
defp do_unfollow(follower, followed, activity_id, false) do
# On a remote unfollow, _remove_ their activity from the database, since some software (MISSKEEEEY)
# uses deterministic ids for follows.
with %Activity{} = follow_activity <- fetch_latest_follow(follower, followed),
{:ok, activity} <- Repo.delete(follow_activity),
unfollow_data <- make_unfollow_data(follower, followed, follow_activity, activity_id),
unfollow_activity <- remote_unfollow_data(unfollow_data),
_ <- notify_and_stream(unfollow_activity)
do
{:ok, activity}
else
nil -> nil
{:error, error} -> Repo.rollback(error)
end
end
defp remote_unfollow_data(data) do
{recipients, _, _} = get_recipients(data)
%Activity{
data: data,
local: false,
actor: data["actor"],
recipients: recipients
}
end
@spec flag(map()) :: {:ok, Activity.t()} | {:error, any()}
def flag(params) do
with {:ok, result} <- Repo.transaction(fn -> do_flag(params) end) do

View file

@ -0,0 +1,33 @@
defmodule Pleroma.Repo.Migrations.RemoveRemoteCancelledFollowRequests do
use Ecto.Migration
def up do
statement = """
DELETE FROM
activities
WHERE
(data->>'type') = 'Follow'
AND
(data->>'state') = 'cancelled'
AND
local = false;
"""
execute(statement)
statement = """
DELETE FROM
activities
WHERE
(data->>'type') = 'Undo'
AND
(data->'object'->>'type') = 'Follow'
AND
local = false;
"""
execute(statement)
end
def down do
:ok
end
end