From 596698a634b7df473a53cf5666138f729cfb4e42 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Thu, 26 Aug 2021 22:28:48 -0400 Subject: [PATCH] Handle Undo Follow activities --- lib/clacks/inbox.ex | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/clacks/inbox.ex b/lib/clacks/inbox.ex index 8218dd9..5fa8358 100644 --- a/lib/clacks/inbox.ex +++ b/lib/clacks/inbox.ex @@ -123,6 +123,33 @@ defmodule Clacks.Inbox do end end + def handle( + %{ + "type" => "Undo", + "actor" => follower_id, + "object" => %{"type" => "Follow", "object" => followee_id} + } = activity + ) + when is_binary(followee_id) do + followee = Actor.get_by_ap_id(followee_id) + + store_activity(activity) + + changeset = + Actor.changeset(followee, %{ + followers: List.delete(followee.followers, follower_id) + }) + + case Repo.update(changeset) do + {:error, changeset} -> + Logger.error("Couldn't store updated followers: #{inspect(changeset)}") + {:error, "Couldn't store updated followers"} + + {:ok, _followee} -> + :ok + end + end + # as a fallback, just store the activity def handle(activity) do Logger.debug("Unhandled activity: #{inspect(activity)}")