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.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, {:array, :string}, default: [])
19 field(:cc, {:array, :string}, default: [])
21 # is this actually needed?
22 field(:bto, {:array, :string}, default: [])
23 field(:bcc, {:array, :string}, default: [])
27 field(:inReplyTo, :string)
28 field(:attributedTo, ObjectValidators.ObjectID)
30 # TODO: Remove actor on objects
31 field(:actor, ObjectValidators.ObjectID)
34 def cast_and_apply(data) do
37 |> apply_action(:insert)
40 def cast_and_validate(data) do
46 def cast_data(data) do
51 def changeset(struct, data) do
53 |> cast(data, __schema__(:fields))
56 def validate_data(data_cng) do
58 |> validate_inclusion(:type, ["Answer"])
59 |> validate_required([:id, :inReplyTo, :name, :attributedTo, :actor])
60 |> CommonValidations.validate_any_presence([:cc, :to])
61 |> CommonValidations.validate_fields_match([:actor, :attributedTo])
62 |> CommonValidations.validate_actor_presence()
63 |> CommonValidations.validate_host_match()