architex/lib/matrix_server_web/client/request/create_room.ex

49 lines
1.2 KiB
Elixir
Raw Normal View History

defmodule MatrixServerWeb.Client.Request.CreateRoom do
2021-07-10 21:16:00 +00:00
use Ecto.Schema
import Ecto.Changeset
alias Ecto.Changeset
@type t :: %__MODULE__{
visibility: String.t(),
room_alias_name: String.t(),
name: String.t(),
topic: String.t(),
invite: list(String.t()),
room_version: String.t(),
preset: String.t()
}
2021-07-10 21:16:00 +00:00
@primary_key false
embedded_schema do
field :visibility, :string
field :room_alias_name, :string
field :name, :string
field :topic, :string
field :invite, {:array, :string}
field :room_version, :string
2021-07-27 10:55:36 +00:00
field :preset, :string
2021-07-10 21:16:00 +00:00
# TODO: unimplemented:
2021-07-27 10:55:36 +00:00
# creation_content, initial_state, invite_3pid, initial_state,
2021-07-10 21:16:00 +00:00
# is_direct, power_level_content_override
end
def changeset(params) do
%__MODULE__{}
2021-07-27 10:55:36 +00:00
|> cast(params, [
:visibility,
:room_alias_name,
:name,
:topic,
:invite,
:room_version,
:preset
])
|> validate_inclusion(:preset, ["private_chat", "public_chat", "trusted_private_chat"])
2021-07-10 21:16:00 +00:00
end
def get_error(%Changeset{errors: [error | _]}), do: get_error(error)
def get_error(_), do: :bad_json
end