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.ActivityPub
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)
29 # - Delete and unpins the create activity
30 # - Replace object with Tombstone
31 # - Set up notification
32 # - Reduce the user note count
33 # - Reduce the reply count
34 # - Stream out the activity
35 def handle(%{data: %{"type" => "Delete", "object" => deleted_object}} = object, meta) do
37 Object.normalize(deleted_object, false) || User.get_cached_by_ap_id(deleted_object)
40 case deleted_object do
42 with {:ok, deleted_object, activity} <- Object.delete(deleted_object),
43 %User{} = user <- User.get_cached_by_ap_id(deleted_object.data["actor"]) do
44 User.remove_pinnned_activity(user, activity)
46 {:ok, user} = ActivityPub.decrease_note_count_if_public(user, deleted_object)
48 if in_reply_to = deleted_object.data["inReplyTo"] do
49 Object.decrease_replies_count(in_reply_to)
52 ActivityPub.stream_out(object)
53 ActivityPub.stream_out_participations(deleted_object, user)
58 with {:ok, _} <- User.delete(deleted_object) do
64 Notification.create_notifications(object)
72 def handle(object, meta) do