Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into develop
[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 {:ok, result} =
19 Pleroma.Repo.transaction(fn ->
20 liked_object = Object.get_by_ap_id(object.data["object"])
21 Utils.add_like_to_object(object, liked_object)
22
23 Notification.create_notifications(object)
24
25 {:ok, object, meta}
26 end)
27
28 result
29 end
30
31 # Nothing to do
32 def handle(object, meta) do
33 {:ok, object, meta}
34 end
35 end