1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.ObjectValidators.NoteValidator do
8 alias Pleroma.EctoType.ActivityPub.ObjectValidators
9 alias Pleroma.Web.ActivityPub.Transmogrifier
16 field(:id, ObjectValidators.ObjectID, primary_key: true)
17 field(:to, ObjectValidators.Recipients, default: [])
18 field(:cc, ObjectValidators.Recipients, default: [])
19 field(:bto, ObjectValidators.Recipients, default: [])
20 field(:bcc, ObjectValidators.Recipients, default: [])
22 field(:tag, {:array, :map}, default: [])
26 field(:summary, :string)
27 field(:content, :string)
29 field(:context, :string)
30 # short identifier for PleromaFE to group statuses by context
31 field(:context_id, :integer)
33 field(:actor, ObjectValidators.ObjectID)
34 field(:attributedTo, ObjectValidators.ObjectID)
35 field(:published, ObjectValidators.DateTime)
36 field(:emoji, ObjectValidators.Emoji, default: %{})
37 field(:sensitive, :boolean, default: false)
39 field(:attachment, {:array, :map}, default: [])
40 field(:replies_count, :integer, default: 0)
41 field(:like_count, :integer, default: 0)
42 field(:announcement_count, :integer, default: 0)
43 field(:inReplyTo, ObjectValidators.ObjectID)
44 field(:url, ObjectValidators.Uri)
46 field(:likes, {:array, :string}, default: [])
47 field(:announcements, {:array, :string}, default: [])
50 def cast_and_validate(data) do
58 |> Transmogrifier.fix_emoji()
61 def cast_data(data) do
65 |> cast(data, __schema__(:fields))
68 def validate_data(data_cng) do
70 |> validate_inclusion(:type, ["Note"])
71 |> validate_required([:id, :actor, :to, :cc, :type, :content, :context])