1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
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
10 # Activities and Objects
11 defmacro message_fields do
12 quote bind_quoted: binding() do
14 field(:id, ObjectValidators.ObjectID, primary_key: true)
16 field(:to, ObjectValidators.Recipients, default: [])
17 field(:cc, ObjectValidators.Recipients, default: [])
18 field(:bto, ObjectValidators.Recipients, default: [])
19 field(:bcc, ObjectValidators.Recipients, default: [])
23 defmacro activity_fields do
24 quote bind_quoted: binding() do
25 field(:object, ObjectValidators.ObjectID)
26 field(:actor, ObjectValidators.ObjectID)
30 # All objects except Answer and CHatMessage
31 defmacro object_fields do
32 quote bind_quoted: binding() do
33 field(:content, :string)
35 field(:published, ObjectValidators.DateTime)
36 field(:updated, ObjectValidators.DateTime)
37 field(:emoji, ObjectValidators.Emoji, default: %{})
38 embeds_many(:attachment, AttachmentValidator)
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)
49 embeds_many(:tag, TagValidator)
52 field(:summary, :string)
54 field(:context, :string)
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)
64 field(:likes, {:array, ObjectValidators.ObjectID}, default: [])
65 field(:announcements, {:array, ObjectValidators.ObjectID}, default: [])
69 defmacro tag_fields do
70 quote bind_quoted: binding() do
71 embeds_many(:tag, TagValidator)