Handle Undo Follow activities
This commit is contained in:
parent
59116cce2e
commit
596698a634
|
@ -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)}")
|
||||
|
|
Loading…
Reference in New Issue