b15343c070821f81e590873da67fcb6d23fd65c7
[akkoma] / lib / pleroma / web / activity_pub / side_effects.ex
1 defmodule Pleroma.Web.ActivityPub.SideEffects do
2 @moduledoc """
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
6 collection, and so on.
7 """
8 alias Pleroma.Notification
9 alias Pleroma.Object
10 alias Pleroma.Web.ActivityPub.Utils
11
12 def handle(object, meta \\ [])
13
14 # Tasks this handles:
15 # - Add like to object
16 # - Set up notification
17 def handle(%{data: %{"type" => "Like"}} = object, meta) do
18 liked_object = Object.get_by_ap_id(object.data["object"])
19 Utils.add_like_to_object(object, liked_object)
20
21 Notification.create_notifications(object)
22
23 {:ok, object, meta}
24 end
25
26 # Tasks this handles:
27 # - Add reaction to object
28 # - Set up notification
29 def handle(%{data: %{"type" => "EmojiReact"}} = object, meta) do
30 reacted_object = Object.get_by_ap_id(object.data["object"])
31 Utils.add_emoji_reaction_to_object(object, reacted_object)
32
33 Notification.create_notifications(object)
34
35 {:ok, object, meta}
36 end
37
38 # Nothing to do
39 def handle(object, meta) do
40 {:ok, object, meta}
41 end
42 end