2021-09-01 12:43:55 +00:00
|
|
|
defmodule ArchitexWeb.Client.Request.CreateRoom do
|
2021-09-09 15:26:40 +00:00
|
|
|
use ArchitexWeb.APIRequest
|
2021-07-10 21:16:00 +00:00
|
|
|
|
2021-09-13 10:42:56 +00:00
|
|
|
alias Architex.Types.UserId
|
|
|
|
|
2021-09-12 09:54:05 +00:00
|
|
|
defmodule PowerLevelContentOverride do
|
|
|
|
use Ecto.Schema
|
|
|
|
|
|
|
|
defmodule Notifications do
|
|
|
|
use Ecto.Schema
|
|
|
|
|
|
|
|
@type t :: %__MODULE__{
|
|
|
|
room: integer() | nil
|
|
|
|
}
|
|
|
|
|
|
|
|
@primary_key false
|
|
|
|
embedded_schema do
|
|
|
|
field :room, :integer
|
|
|
|
end
|
|
|
|
|
|
|
|
def changeset(data, params) do
|
|
|
|
cast(data, params, [:room])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
@type t :: %__MODULE__{
|
|
|
|
ban: integer() | nil,
|
|
|
|
events: %{optional(String.t()) => integer()} | nil,
|
|
|
|
events_default: integer() | nil,
|
|
|
|
invite: integer() | nil,
|
|
|
|
kick: integer() | nil,
|
|
|
|
redact: integer() | nil,
|
|
|
|
state_default: integer() | nil,
|
|
|
|
users: %{optional(String.t()) => integer()} | nil,
|
|
|
|
users_default: integer() | nil,
|
|
|
|
notifications: Notifications.t() | nil
|
|
|
|
}
|
|
|
|
|
|
|
|
@primary_key false
|
|
|
|
embedded_schema do
|
|
|
|
field :ban, :integer
|
|
|
|
field :events, {:map, :integer}
|
|
|
|
field :events_default, :integer
|
|
|
|
field :invite, :integer
|
|
|
|
field :kick, :integer
|
|
|
|
field :redact, :integer
|
|
|
|
field :state_default, :integer
|
|
|
|
field :users, {:map, :integer}
|
|
|
|
field :users_default, :integer
|
|
|
|
|
|
|
|
embeds_one :notifications, Notifications
|
|
|
|
end
|
|
|
|
|
|
|
|
def changeset(data, params) do
|
|
|
|
data
|
|
|
|
|> cast(params, [
|
|
|
|
:ban,
|
|
|
|
:events,
|
|
|
|
:events_default,
|
|
|
|
:invite,
|
|
|
|
:kick,
|
|
|
|
:redact,
|
|
|
|
:state_default,
|
|
|
|
:users,
|
|
|
|
:users_default
|
|
|
|
])
|
|
|
|
|> cast_embed(:notifications,
|
|
|
|
with: &Notifications.changeset/2,
|
|
|
|
required: false
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defmodule StateEvent do
|
|
|
|
use Ecto.Schema
|
|
|
|
|
|
|
|
@type t :: %__MODULE__{
|
|
|
|
type: String.t(),
|
|
|
|
state_key: String.t(),
|
|
|
|
content: %{optional(String.t()) => any()}
|
|
|
|
}
|
|
|
|
|
|
|
|
@primary_key false
|
|
|
|
embedded_schema do
|
|
|
|
field :type, :string
|
|
|
|
field :state_key, :string, default: ""
|
|
|
|
field :content, :map
|
|
|
|
end
|
|
|
|
|
|
|
|
def changeset(data, params) do
|
|
|
|
data
|
|
|
|
|> cast(params, [:type, :state_key, :content])
|
|
|
|
|> validate_required([:type, :content])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
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,
|
2021-09-13 10:42:56 +00:00
|
|
|
invite: [UserId.t()] | nil,
|
2021-09-05 14:39:52 +00:00
|
|
|
room_version: String.t() | nil,
|
2021-09-11 13:11:38 +00:00
|
|
|
preset: String.t() | nil,
|
2021-09-11 15:38:25 +00:00
|
|
|
is_direct: boolean() | nil,
|
2021-09-11 16:23:51 +00:00
|
|
|
creation_content: %{optional(String.t()) => any()} | nil,
|
2021-09-12 09:54:05 +00:00
|
|
|
power_level_content_override: PowerLevelContentOverride.t() | nil,
|
|
|
|
initial_state: [StateEvent.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
|
2021-09-12 09:54:05 +00:00
|
|
|
# TODO: unimplemented: invite_3pid and room_alias_name
|
2021-07-10 21:16:00 +00:00
|
|
|
field :visibility, :string
|
|
|
|
field :room_alias_name, :string
|
|
|
|
field :name, :string
|
|
|
|
field :topic, :string
|
2021-09-13 10:42:56 +00:00
|
|
|
field :invite, {:array, UserId}
|
2021-07-10 21:16:00 +00:00
|
|
|
field :room_version, :string
|
2021-07-27 10:55:36 +00:00
|
|
|
field :preset, :string
|
2021-09-11 15:38:25 +00:00
|
|
|
field :is_direct, :boolean
|
2021-09-11 16:23:51 +00:00
|
|
|
field :creation_content, :map
|
2021-09-11 13:11:38 +00:00
|
|
|
|
2021-09-12 09:54:05 +00:00
|
|
|
embeds_many :initial_state, StateEvent
|
|
|
|
embeds_one :power_level_content_override, PowerLevelContentOverride
|
2021-07-10 21:16:00 +00:00
|
|
|
end
|
|
|
|
|
2021-09-09 15:26:40 +00:00
|
|
|
def changeset(data, params) do
|
|
|
|
data
|
2021-07-27 10:55:36 +00:00
|
|
|
|> cast(params, [
|
|
|
|
:visibility,
|
|
|
|
:room_alias_name,
|
|
|
|
:name,
|
|
|
|
:topic,
|
|
|
|
:invite,
|
|
|
|
:room_version,
|
2021-09-11 15:38:25 +00:00
|
|
|
:preset,
|
2021-09-11 16:23:51 +00:00
|
|
|
:is_direct,
|
|
|
|
:creation_content
|
2021-07-27 10:55:36 +00:00
|
|
|
])
|
2021-09-11 13:11:38 +00:00
|
|
|
|> cast_embed(:power_level_content_override,
|
2021-09-12 09:54:05 +00:00
|
|
|
with: &PowerLevelContentOverride.changeset/2,
|
2021-09-11 13:11:38 +00:00
|
|
|
required: false
|
|
|
|
)
|
2021-09-12 09:54:05 +00:00
|
|
|
|> cast_embed(:initial_state, with: &StateEvent.changeset/2, required: false)
|
2021-07-27 10:55:36 +00:00
|
|
|
|> validate_inclusion(:preset, ["private_chat", "public_chat", "trusted_private_chat"])
|
2021-07-10 21:16:00 +00:00
|
|
|
end
|
|
|
|
end
|