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
12 alias Pleroma.Web.ActivityPub.ActivityPub
14 def handle(object, meta \\ [])
17 # - Add like to object
18 # - Set up notification
19 def handle(%{data: %{"type" => "Like"}} = object, meta) do
21 Pleroma.Repo.transaction(fn ->
22 liked_object = Object.get_by_ap_id(object.data["object"])
23 Utils.add_like_to_object(object, liked_object)
25 Notification.create_notifications(object)
34 # - Delete and unpins the create activity
35 # - Replace object with Tombstone
36 # - Set up notification
37 # - Reduce the user note count
38 def handle(%{data: %{"type" => "Delete", "object" => deleted_object}} = object, meta) do
40 Object.normalize(deleted_object, false) || User.get_cached_by_ap_id(deleted_object)
43 case deleted_object do
45 with {:ok, deleted_object, activity} <- Object.delete(deleted_object),
46 %User{} = user <- User.get_cached_by_ap_id(deleted_object.data["actor"]) do
47 User.remove_pinnned_activity(user, activity)
49 {:ok, user} = ActivityPub.decrease_note_count_if_public(user, deleted_object)
50 ActivityPub.stream_out(object)
51 ActivityPub.stream_out_participations(deleted_object, user)
56 with {:ok, _} <- User.delete(deleted_object) do
62 Notification.create_notifications(object)
70 def handle(object, meta) do