Merge pull request 'Add PWA config' (#329) from pwa into develop
[akkoma] / lib / pleroma / web / activity_pub / object_validators / common_fields.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.ObjectValidators.CommonFields do
6 alias Pleroma.EctoType.ActivityPub.ObjectValidators
7 alias Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator
8 alias Pleroma.Web.ActivityPub.ObjectValidators.TagValidator
9
10 # Activities and Objects
11 defmacro message_fields do
12 quote bind_quoted: binding() do
13 field(:type, :string)
14 field(:id, ObjectValidators.ObjectID, primary_key: true)
15
16 field(:to, ObjectValidators.Recipients, default: [])
17 field(:cc, ObjectValidators.Recipients, default: [])
18 field(:bto, ObjectValidators.Recipients, default: [])
19 field(:bcc, ObjectValidators.Recipients, default: [])
20 end
21 end
22
23 defmacro activity_fields do
24 quote bind_quoted: binding() do
25 field(:object, ObjectValidators.ObjectID)
26 field(:actor, ObjectValidators.ObjectID)
27 end
28 end
29
30 # All objects except Answer and CHatMessage
31 defmacro object_fields do
32 quote bind_quoted: binding() do
33 field(:content, :string)
34
35 field(:published, ObjectValidators.DateTime)
36 field(:updated, ObjectValidators.DateTime)
37 field(:emoji, ObjectValidators.Emoji, default: %{})
38 embeds_many(:attachment, AttachmentValidator)
39 end
40 end
41
42 # Basically objects that aren't Answer
43 defmacro status_object_fields do
44 quote bind_quoted: binding() do
45 # TODO: Remove actor on objects
46 field(:actor, ObjectValidators.ObjectID)
47 field(:attributedTo, ObjectValidators.ObjectID)
48
49 embeds_many(:tag, TagValidator)
50
51 field(:name, :string)
52 field(:summary, :string)
53
54 field(:context, :string)
55
56 field(:sensitive, :boolean, default: false)
57 field(:replies_count, :integer, default: 0)
58 field(:like_count, :integer, default: 0)
59 field(:announcement_count, :integer, default: 0)
60 field(:inReplyTo, ObjectValidators.ObjectID)
61 field(:quoteUri, ObjectValidators.ObjectID)
62 field(:url, ObjectValidators.Uri)
63
64 field(:likes, {:array, ObjectValidators.ObjectID}, default: [])
65 field(:announcements, {:array, ObjectValidators.ObjectID}, default: [])
66 end
67 end
68
69 defmacro tag_fields do
70 quote bind_quoted: binding() do
71 embeds_many(:tag, TagValidator)
72 end
73 end
74 end