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.AnswerValidator do
8 alias Pleroma.EctoType.ActivityPub.ObjectValidators
9 alias Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
17 field(:id, ObjectValidators.ObjectID, primary_key: true)
18 field(:to, ObjectValidators.Recipients, default: [])
19 field(:cc, ObjectValidators.Recipients, default: [])
20 field(:bto, ObjectValidators.Recipients, default: [])
21 field(:bcc, ObjectValidators.Recipients, default: [])
24 field(:inReplyTo, ObjectValidators.ObjectID)
25 field(:attributedTo, ObjectValidators.ObjectID)
27 # TODO: Remove actor on objects
28 field(:actor, ObjectValidators.ObjectID)
31 def cast_and_apply(data) do
34 |> apply_action(:insert)
37 def cast_and_validate(data) do
43 def cast_data(data) do
48 def changeset(struct, data) do
50 |> cast(data, __schema__(:fields))
53 defp validate_data(data_cng) do
55 |> validate_inclusion(:type, ["Answer"])
56 |> validate_required([:id, :inReplyTo, :name, :attributedTo, :actor])
57 |> CommonValidations.validate_any_presence([:cc, :to])
58 |> CommonValidations.validate_fields_match([:actor, :attributedTo])
59 |> CommonValidations.validate_actor_presence()
60 |> CommonValidations.validate_host_match()