1 defmodule Pleroma.Web.ActivityPub.Builder do
3 This module builds the objects. Meant to be used for creating local objects.
5 This module encodes our addressing policies and general shape of our objects.
10 alias Pleroma.Web.ActivityPub.Utils
11 alias Pleroma.Web.ActivityPub.Visibility
13 @spec undo(User.t(), Activity.t()) :: {:ok, map(), keyword()}
14 def undo(actor, object) do
17 "id" => Utils.generate_activity_id(),
18 "actor" => actor.ap_id,
20 "object" => object.data["id"],
21 "to" => object.data["to"] || [],
22 "cc" => object.data["cc"] || []
26 @spec delete(User.t(), String.t()) :: {:ok, map(), keyword()}
27 def delete(actor, object_id) do
28 object = Object.normalize(object_id, false)
30 user = !object && User.get_cached_by_ap_id(object_id)
33 case {object, user} do
35 # We are deleting an object, address everyone who was originally mentioned
36 (object.data["to"] || []) ++ (object.data["cc"] || [])
38 {_, %User{follower_address: follower_address}} ->
39 # We are deleting a user, address the followers of that user
45 "id" => Utils.generate_activity_id(),
46 "actor" => actor.ap_id,
47 "object" => object_id,
53 @spec like(User.t(), Object.t()) :: {:ok, map(), keyword()}
54 def like(actor, object) do
55 object_actor = User.get_cached_by_ap_id(object.data["actor"])
57 # Address the actor of the object, and our actor's follower collection if the post is public.
59 if Visibility.is_public?(object) do
60 [actor.follower_address, object.data["actor"]]
62 [object.data["actor"]]
65 # CC everyone who's been addressed in the object, except ourself and the object actor's
68 (object.data["to"] ++ (object.data["cc"] || []))
69 |> List.delete(actor.ap_id)
70 |> List.delete(object_actor.follower_address)
74 "id" => Utils.generate_activity_id(),
75 "actor" => actor.ap_id,
77 "object" => object.data["id"],
80 "context" => object.data["context"]