akkoma/lib/pleroma/web/activity_pub/object_validators/create_chat_message_validator.ex

36 lines
953 B
Elixir
Raw Normal View History

2019-12-09 09:39:14 +00:00
# Pleroma: A lightweight social networking server
2020-03-26 14:37:42 +00:00
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
2019-12-09 09:39:14 +00:00
# SPDX-License-Identifier: AGPL-3.0-only
2020-04-08 13:55:43 +00:00
# NOTES
# - Can probably be a generic create validator
# - doesn't embed, will only get the object id
# - object has to be validated first, maybe with some meta info from the surrounding create
defmodule Pleroma.Web.ActivityPub.ObjectValidators.CreateChatMessageValidator do
2019-12-09 09:39:14 +00:00
use Ecto.Schema
2020-03-19 17:16:12 +00:00
alias Pleroma.Web.ActivityPub.ObjectValidators.Types
2019-12-09 09:39:14 +00:00
import Ecto.Changeset
@primary_key false
embedded_schema do
2020-03-26 14:44:14 +00:00
field(:id, Types.ObjectID, primary_key: true)
2019-12-09 09:39:14 +00:00
field(:actor, Types.ObjectID)
field(:type, :string)
2020-04-08 13:55:43 +00:00
field(:to, Types.Recipients, default: [])
field(:object, Types.ObjectID)
end
2019-12-09 09:39:14 +00:00
2020-04-08 13:55:43 +00:00
def cast_and_apply(data) do
data
|> cast_data
|> apply_action(:insert)
2019-12-09 09:39:14 +00:00
end
def cast_data(data) do
cast(%__MODULE__{}, data, __schema__(:fields))
2019-12-09 09:39:14 +00:00
end
end