Handle Undo Follow activities

This commit is contained in:
Shadowfacts 2021-08-26 22:28:48 -04:00
parent 59116cce2e
commit 596698a634
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 27 additions and 0 deletions

View File

@ -123,6 +123,33 @@ defmodule Clacks.Inbox do
end end
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 # as a fallback, just store the activity
def handle(activity) do def handle(activity) do
Logger.debug("Unhandled activity: #{inspect(activity)}") Logger.debug("Unhandled activity: #{inspect(activity)}")