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 delete(User.t(), String.t()) :: {:ok, map(), keyword()}
14 def delete(actor, object_id) do
15 object = Object.normalize(object_id, false)
17 user = !object && User.get_cached_by_ap_id(object_id)
20 case {object, user} do
22 # We are deleting an object, address everyone who was originally mentioned
23 (object.data["to"] || []) ++ (object.data["cc"] || [])
25 {_, %User{follower_address: follower_address}} ->
26 # We are deleting a user, address the followers of that user
32 "id" => Utils.generate_activity_id(),
33 "actor" => actor.ap_id,
34 "object" => object_id,
40 @spec like(User.t(), Object.t()) :: {:ok, map(), keyword()}
41 def like(actor, object) do
42 object_actor = User.get_cached_by_ap_id(object.data["actor"])
44 # Address the actor of the object, and our actor's follower collection if the post is public.
46 if Visibility.is_public?(object) do
47 [actor.follower_address, object.data["actor"]]
49 [object.data["actor"]]
52 # CC everyone who's been addressed in the object, except ourself and the object actor's
55 (object.data["to"] ++ (object.data["cc"] || []))
56 |> List.delete(actor.ap_id)
57 |> List.delete(object_actor.follower_address)
61 "id" => Utils.generate_activity_id(),
62 "actor" => actor.ap_id,
64 "object" => object.data["id"],
67 "context" => object.data["context"]