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.
11 alias Pleroma.Web.ActivityPub.Utils
12 alias Pleroma.Web.ActivityPub.Visibility
14 def create(actor, object, recipients) do
17 "id" => Utils.generate_activity_id(),
18 "actor" => actor.ap_id,
22 "published" => DateTime.utc_now() |> DateTime.to_iso8601()
26 def chat_message(actor, recipient, content) do
29 "id" => Utils.generate_object_id(),
30 "actor" => actor.ap_id,
31 "type" => "ChatMessage",
34 "published" => DateTime.utc_now() |> DateTime.to_iso8601(),
35 "emoji" => Emoji.Formatter.get_emoji_map(content)
39 @spec like(User.t(), Object.t()) :: {:ok, map(), keyword()}
40 def like(actor, object) do
41 object_actor = User.get_cached_by_ap_id(object.data["actor"])
43 # Address the actor of the object, and our actor's follower collection if the post is public.
45 if Visibility.is_public?(object) do
46 [actor.follower_address, object.data["actor"]]
48 [object.data["actor"]]
51 # CC everyone who's been addressed in the object, except ourself and the object actor's
54 (object.data["to"] ++ (object.data["cc"] || []))
55 |> List.delete(actor.ap_id)
56 |> List.delete(object_actor.follower_address)
60 "id" => Utils.generate_activity_id(),
61 "actor" => actor.ap_id,
63 "object" => object.data["id"],
66 "context" => object.data["context"]