+ 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 <- make_unfollow_activity(unfollow_data, false),
+ _ <- notify_and_stream(unfollow_activity) do
+ {:ok, unfollow_activity}
+ else
+ nil -> nil
+ {:error, error} -> Repo.rollback(error)
+ end
+ end
+
+ defp make_unfollow_activity(data, local) do
+ {recipients, _, _} = get_recipients(data)
+
+ %Activity{
+ data: data,
+ local: local,
+ actor: data["actor"],
+ recipients: recipients
+ }
+ end
+