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
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)
22 Notification.create_notifications(object)
26 def handle(%{data: %{"type" => "Create", "object" => object_id}} = activity, meta) do
27 object = Object.get_by_ap_id(object_id)
29 {:ok, _object} = handle_object_creation(object)
35 def handle(object, meta) do
39 def handle_object_creation(%{data: %{"type" => "ChatMessage"}} = object) do
40 actor = User.get_cached_by_ap_id(object.data["actor"])
41 recipient = User.get_cached_by_ap_id(hd(object.data["to"]))
43 [[actor, recipient], [recipient, actor]]
44 |> Enum.each(fn [user, other_user] ->
46 Chat.bump_or_create(user.id, other_user.ap_id)
54 def handle_object_creation(object) do