1 defmodule Pleroma.Web.ActivityPub.SideEffects do
3 This module looks at an inserted object and executes the side effects that it
4 implies. For example, a `Like` activity will increase the like count on the
5 liked object, a `Follow` activity will add the user to the follower
9 alias Pleroma.Notification
12 alias Pleroma.Web.ActivityPub.Utils
14 def handle(object, meta \\ [])
17 # - Add like to object
18 # - Set up notification
19 def handle(%{data: %{"type" => "Like"}} = object, meta) do
20 liked_object = Object.get_by_ap_id(object.data["object"])
21 Utils.add_like_to_object(object, liked_object)
23 Notification.create_notifications(object)
28 def handle(%{data: %{"type" => "Undo", "object" => undone_object}} = object, meta) do
29 with undone_object <- Activity.get_by_ap_id(undone_object),
30 :ok <- handle_undoing(undone_object) do
36 def handle(object, meta) do
40 def handle_undoing(%{data: %{"type" => "Like"}} = object) do
41 with %Object{} = liked_object <- Object.get_by_ap_id(object.data["object"]),
42 {:ok, _} <- Utils.remove_like_from_object(object, liked_object),
43 {:ok, _} <- Repo.delete(object) do
48 def handle_undoing(object), do: {:error, ["don't know how to handle", object]}