Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into remake-remodel-dms
[akkoma] / lib / pleroma / web / activity_pub / object_validators / create_chat_message_validator.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 # NOTES
6 # - Can probably be a generic create validator
7 # - doesn't embed, will only get the object id
8 # - object has to be validated first, maybe with some meta info from the surrounding create
9 defmodule Pleroma.Web.ActivityPub.ObjectValidators.CreateChatMessageValidator do
10 use Ecto.Schema
11
12 alias Pleroma.Web.ActivityPub.ObjectValidators.Types
13
14 import Ecto.Changeset
15
16 @primary_key false
17
18 embedded_schema do
19 field(:id, Types.ObjectID, primary_key: true)
20 field(:actor, Types.ObjectID)
21 field(:type, :string)
22 field(:to, Types.Recipients, default: [])
23 field(:object, Types.ObjectID)
24 end
25
26 def cast_and_apply(data) do
27 data
28 |> cast_data
29 |> apply_action(:insert)
30 end
31
32 def cast_data(data) do
33 cast(%__MODULE__{}, data, __schema__(:fields))
34 end
35 end