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
8 alias Pleroma.Notification
11 alias Pleroma.Web.ActivityPub.Utils
13 def handle(object, meta \\ [])
16 # - Add like to object
17 # - Set up notification
18 def handle(%{data: %{"type" => "Like"}} = object, meta) do
20 Pleroma.Repo.transaction(fn ->
21 liked_object = Object.get_by_ap_id(object.data["object"])
22 Utils.add_like_to_object(object, liked_object)
24 Notification.create_notifications(object)
33 # - Delete create activity
34 # - Replace object with Tombstone
35 # - Set up notification
36 def handle(%{data: %{"type" => "Delete", "object" => deleted_object}} = object, meta) do
38 Object.normalize(deleted_object, false) || User.get_cached_by_ap_id(deleted_object)
41 case deleted_object do
43 with {:ok, _, _} <- Object.delete(deleted_object) do
48 with {:ok, _} <- User.delete(deleted_object) do
54 Notification.create_notifications(object)
62 def handle(object, meta) do