2021-09-01 12:43:55 +00:00
|
|
|
defmodule ArchitexWeb.Client.Request.CreateRoom do
|
2021-07-10 21:16:00 +00:00
|
|
|
use Ecto.Schema
|
|
|
|
|
|
|
|
import Ecto.Changeset
|
|
|
|
|
|
|
|
alias Ecto.Changeset
|
|
|
|
|
2021-08-18 21:22:04 +00:00
|
|
|
@type t :: %__MODULE__{
|
2021-09-05 14:39:52 +00:00
|
|
|
visibility: String.t() | nil,
|
|
|
|
room_alias_name: String.t() | nil,
|
|
|
|
name: String.t() | nil,
|
|
|
|
topic: String.t() | nil,
|
|
|
|
invite: list(String.t()) | nil,
|
|
|
|
room_version: String.t() | nil,
|
|
|
|
preset: String.t() | nil
|
2021-08-19 14:31:03 +00:00
|
|
|
}
|
2021-08-18 21:22:04 +00:00
|
|
|
|
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
|