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 @spec delete(User.t(), String.t()) :: {:ok, map(), keyword()}
15 def delete(actor, object_id) do
16 object = Object.normalize(object_id, false)
18 user = !object && User.get_cached_by_ap_id(object_id)
21 case {object, user} do
23 # We are deleting an object, address everyone who was originally mentioned
24 (object.data["to"] || []) ++ (object.data["cc"] || [])
26 {_, %User{follower_address: follower_address}} ->
27 # We are deleting a user, address the followers of that user
33 "id" => Utils.generate_activity_id(),
34 "actor" => actor.ap_id,
35 "object" => object_id,
41 def create(actor, object, recipients) do
44 "id" => Utils.generate_activity_id(),
45 "actor" => actor.ap_id,
49 "published" => DateTime.utc_now() |> DateTime.to_iso8601()
53 def chat_message(actor, recipient, content, opts \\ []) do
55 "id" => Utils.generate_object_id(),
56 "actor" => actor.ap_id,
57 "type" => "ChatMessage",
60 "published" => DateTime.utc_now() |> DateTime.to_iso8601(),
61 "emoji" => Emoji.Formatter.get_emoji_map(content)
64 case opts[:attachment] do
65 %Object{data: attachment_data} ->
68 Map.put(basic, "attachment", attachment_data),
77 @spec like(User.t(), Object.t()) :: {:ok, map(), keyword()}
78 def like(actor, object) do
79 object_actor = User.get_cached_by_ap_id(object.data["actor"])
81 # Address the actor of the object, and our actor's follower collection if the post is public.
83 if Visibility.is_public?(object) do
84 [actor.follower_address, object.data["actor"]]
86 [object.data["actor"]]
89 # CC everyone who's been addressed in the object, except ourself and the object actor's
92 (object.data["to"] ++ (object.data["cc"] || []))
93 |> List.delete(actor.ap_id)
94 |> List.delete(object_actor.follower_address)
98 "id" => Utils.generate_activity_id(),
99 "actor" => actor.ap_id,
101 "object" => object.data["id"],
104 "context" => object.data["context"]