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, opts \\ []) do
28 "id" => Utils.generate_object_id(),
29 "actor" => actor.ap_id,
30 "type" => "ChatMessage",
33 "published" => DateTime.utc_now() |> DateTime.to_iso8601(),
34 "emoji" => Emoji.Formatter.get_emoji_map(content)
37 case opts[:attachment] do
38 %Object{data: attachment_data} ->
41 Map.put(basic, "attachment", attachment_data),
50 @spec like(User.t(), Object.t()) :: {:ok, map(), keyword()}
51 def like(actor, object) do
52 object_actor = User.get_cached_by_ap_id(object.data["actor"])
54 # Address the actor of the object, and our actor's follower collection if the post is public.
56 if Visibility.is_public?(object) do
57 [actor.follower_address, object.data["actor"]]
59 [object.data["actor"]]
62 # CC everyone who's been addressed in the object, except ourself and the object actor's
65 (object.data["to"] ++ (object.data["cc"] || []))
66 |> List.delete(actor.ap_id)
67 |> List.delete(object_actor.follower_address)
71 "id" => Utils.generate_activity_id(),
72 "actor" => actor.ap_id,
74 "object" => object.data["id"],
77 "context" => object.data["context"]