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
9 alias Pleroma.Notification
13 alias Pleroma.Web.ActivityPub.Pipeline
14 alias Pleroma.Web.ActivityPub.Utils
16 def handle(object, meta \\ [])
19 # - Add like to object
20 # - Set up notification
21 def handle(%{data: %{"type" => "Like"}} = object, meta) do
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)
31 # - Actually create object
32 # - Rollback if we couldn't create it
33 # - Set up notifications
34 def handle(%{data: %{"type" => "Create"}} = activity, meta) do
35 with {:ok, _object, _meta} <- handle_object_creation(meta[:object_data], meta) do
36 Notification.create_notifications(activity)
44 def handle(object, meta) do
48 def handle_object_creation(%{"type" => "ChatMessage"} = object, meta) do
49 with {:ok, object, meta} <- Pipeline.common_pipeline(object, meta) do
50 actor = User.get_cached_by_ap_id(object.data["actor"])
51 recipient = User.get_cached_by_ap_id(hd(object.data["to"]))
53 [[actor, recipient], [recipient, actor]]
54 |> Enum.each(fn [user, other_user] ->
56 Chat.bump_or_create(user.id, other_user.ap_id)
65 def handle_object_creation(object) do