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.EventValidator do
8 alias Pleroma.EctoType.ActivityPub.ObjectValidators
9 alias Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator
10 alias Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes
11 alias Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
18 # Extends from NoteValidator
20 field(:id, ObjectValidators.ObjectID, primary_key: true)
21 field(:to, ObjectValidators.Recipients, default: [])
22 field(:cc, ObjectValidators.Recipients, default: [])
23 field(:bto, ObjectValidators.Recipients, default: [])
24 field(:bcc, ObjectValidators.Recipients, default: [])
26 field(:tag, {:array, :map}, default: [])
30 field(:summary, :string)
31 field(:content, :string)
33 field(:context, :string)
34 # short identifier for PleromaFE to group statuses by context
35 field(:context_id, :integer)
37 # TODO: Remove actor on objects
38 field(:actor, ObjectValidators.ObjectID)
40 field(:attributedTo, ObjectValidators.ObjectID)
41 field(:published, ObjectValidators.DateTime)
43 field(:emoji, :map, default: %{})
44 field(:sensitive, :boolean, default: false)
45 embeds_many(:attachment, AttachmentValidator)
46 field(:replies_count, :integer, default: 0)
47 field(:like_count, :integer, default: 0)
48 field(:announcement_count, :integer, default: 0)
49 field(:inReplyTo, ObjectValidators.ObjectID)
50 field(:url, ObjectValidators.Uri)
52 field(:likes, {:array, ObjectValidators.ObjectID}, default: [])
53 field(:announcements, {:array, ObjectValidators.ObjectID}, default: [])
56 def cast_and_apply(data) do
59 |> apply_action(:insert)
62 def cast_and_validate(data) do
68 def cast_data(data) do
75 |> CommonFixes.fix_defaults()
76 |> CommonFixes.fix_attribution()
79 def changeset(struct, data) do
83 |> cast(data, __schema__(:fields) -- [:attachment])
84 |> cast_embed(:attachment)
87 def validate_data(data_cng) do
89 |> validate_inclusion(:type, ["Event"])
90 |> validate_required([:id, :actor, :attributedTo, :type, :context, :context_id])
91 |> CommonValidations.validate_any_presence([:cc, :to])
92 |> CommonValidations.validate_fields_match([:actor, :attributedTo])
93 |> CommonValidations.validate_actor_presence()
94 |> CommonValidations.validate_host_match()