1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 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.CommonFixes
10 alias Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
20 import Elixir.Pleroma.Web.ActivityPub.ObjectValidators.CommonFields
26 field(:inReplyTo, ObjectValidators.ObjectID)
27 field(:attributedTo, ObjectValidators.ObjectID)
28 field(:context, :string)
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
54 |> CommonFixes.fix_actor()
55 |> CommonFixes.fix_object_defaults()
58 |> cast(data, __schema__(:fields))
61 defp validate_data(data_cng) do
63 |> validate_inclusion(:type, ["Answer"])
64 |> validate_required([:id, :inReplyTo, :name, :attributedTo, :actor])
65 |> CommonValidations.validate_any_presence([:cc, :to])
66 |> CommonValidations.validate_fields_match([:actor, :attributedTo])
67 |> CommonValidations.validate_actor_presence()
68 |> CommonValidations.validate_host_match()