UndoValidator: Add UndoValidator.
[akkoma] / lib / pleroma / web / activity_pub / builder.ex
1 defmodule Pleroma.Web.ActivityPub.Builder do
2 @moduledoc """
3 This module builds the objects. Meant to be used for creating local objects.
4
5 This module encodes our addressing policies and general shape of our objects.
6 """
7
8 alias Pleroma.Object
9 alias Pleroma.User
10 alias Pleroma.Web.ActivityPub.Utils
11 alias Pleroma.Web.ActivityPub.Visibility
12
13 @spec undo(User.t(), Activity.t()) :: {:ok, map(), keyword()}
14 def undo(actor, object) do
15 {:ok,
16 %{
17 "id" => Utils.generate_activity_id(),
18 "actor" => actor.ap_id,
19 "type" => "Undo",
20 "object" => object.data["id"],
21 "to" => object.data["to"] || [],
22 "cc" => object.data["cc"] || []
23 }, []}
24 end
25
26 @spec like(User.t(), Object.t()) :: {:ok, map(), keyword()}
27 def like(actor, object) do
28 object_actor = User.get_cached_by_ap_id(object.data["actor"])
29
30 # Address the actor of the object, and our actor's follower collection if the post is public.
31 to =
32 if Visibility.is_public?(object) do
33 [actor.follower_address, object.data["actor"]]
34 else
35 [object.data["actor"]]
36 end
37
38 # CC everyone who's been addressed in the object, except ourself and the object actor's
39 # follower collection
40 cc =
41 (object.data["to"] ++ (object.data["cc"] || []))
42 |> List.delete(actor.ap_id)
43 |> List.delete(object_actor.follower_address)
44
45 {:ok,
46 %{
47 "id" => Utils.generate_activity_id(),
48 "actor" => actor.ap_id,
49 "type" => "Like",
50 "object" => object.data["id"],
51 "to" => to,
52 "cc" => cc,
53 "context" => object.data["context"]
54 }, []}
55 end
56 end