Implement creation_content option for client room creation
This commit is contained in:
parent
d23a42e29c
commit
8dfd770fd0
4 changed files with 28 additions and 12 deletions
|
@ -50,7 +50,7 @@ Here, implemented and some unimplemented features are listed.
|
||||||
- GET /_matrix/client/r0/login
|
- GET /_matrix/client/r0/login
|
||||||
- POST /_matrix/client/r0/login: Only with password flow.
|
- POST /_matrix/client/r0/login: Only with password flow.
|
||||||
- POST /_matrix/client/r0/register: Only with dummy flow.
|
- POST /_matrix/client/r0/register: Only with dummy flow.
|
||||||
- POST /_matrix/client/r0/createRoom: Except creation_content, initial_state, invite_3pid and initial_state.
|
- POST /_matrix/client/r0/createRoom: Except with options invite_3pid, initial_state and room_alias_name.
|
||||||
- GET /_matrix/client/r0/joined_rooms
|
- GET /_matrix/client/r0/joined_rooms
|
||||||
- POST /_matrix/client/r0/rooms/{roomId}/invite
|
- POST /_matrix/client/r0/rooms/{roomId}/invite
|
||||||
- POST /_matrix/client/r0/rooms/{roomId}/join: Except with third party invite.
|
- POST /_matrix/client/r0/rooms/{roomId}/join: Except with third party invite.
|
||||||
|
|
|
@ -449,11 +449,12 @@ defmodule Architex.RoomServer do
|
||||||
topic: topic,
|
topic: topic,
|
||||||
invite: invite,
|
invite: invite,
|
||||||
power_level_content_override: power_level_content_override,
|
power_level_content_override: power_level_content_override,
|
||||||
is_direct: is_direct
|
is_direct: is_direct,
|
||||||
|
creation_content: creation_content
|
||||||
}) do
|
}) do
|
||||||
events =
|
events =
|
||||||
([
|
([
|
||||||
Event.CreateRoom.new(room, account, room_version),
|
Event.CreateRoom.new(room, account, room_version, creation_content),
|
||||||
Event.Join.new(room, account),
|
Event.Join.new(room, account),
|
||||||
Event.PowerLevels.create_room_new(room, account, power_level_content_override)
|
Event.PowerLevels.create_room_new(room, account, power_level_content_override)
|
||||||
] ++
|
] ++
|
||||||
|
|
|
@ -19,18 +19,31 @@ end
|
||||||
defmodule Architex.Event.CreateRoom do
|
defmodule Architex.Event.CreateRoom do
|
||||||
alias Architex.{Event, Account, Room}
|
alias Architex.{Event, Account, Room}
|
||||||
|
|
||||||
@spec new(Room.t(), Account.t(), String.t()) :: %Event{}
|
@clobber_content_keys ["creator", "room_version"]
|
||||||
def new(room, %Account{localpart: localpart} = creator, room_version) do
|
|
||||||
|
@spec new(Room.t(), Account.t(), String.t(), %{optional(String.t()) => any()} | nil) :: %Event{}
|
||||||
|
def new(room, %Account{localpart: localpart} = creator, room_version, creation_content) do
|
||||||
mxid = Architex.get_mxid(localpart)
|
mxid = Architex.get_mxid(localpart)
|
||||||
|
|
||||||
|
content = %{
|
||||||
|
"creator" => mxid,
|
||||||
|
"room_version" => room_version || Architex.default_room_version()
|
||||||
|
}
|
||||||
|
|
||||||
|
content =
|
||||||
|
if creation_content do
|
||||||
|
creation_content
|
||||||
|
|> Map.drop(@clobber_content_keys)
|
||||||
|
|> Map.merge(content)
|
||||||
|
else
|
||||||
|
content
|
||||||
|
end
|
||||||
|
|
||||||
%Event{
|
%Event{
|
||||||
Event.new(room, creator)
|
Event.new(room, creator)
|
||||||
| type: "m.room.create",
|
| type: "m.room.create",
|
||||||
state_key: "",
|
state_key: "",
|
||||||
content: %{
|
content: content
|
||||||
"creator" => mxid,
|
|
||||||
"room_version" => room_version || Architex.default_room_version()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,6 +10,7 @@ defmodule ArchitexWeb.Client.Request.CreateRoom do
|
||||||
room_version: String.t() | nil,
|
room_version: String.t() | nil,
|
||||||
preset: String.t() | nil,
|
preset: String.t() | nil,
|
||||||
is_direct: boolean() | nil,
|
is_direct: boolean() | nil,
|
||||||
|
creation_content: %{optional(String.t()) => any()} | nil,
|
||||||
power_level_content_override: plco_t() | nil
|
power_level_content_override: plco_t() | nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +41,7 @@ defmodule ArchitexWeb.Client.Request.CreateRoom do
|
||||||
field :room_version, :string
|
field :room_version, :string
|
||||||
field :preset, :string
|
field :preset, :string
|
||||||
field :is_direct, :boolean
|
field :is_direct, :boolean
|
||||||
|
field :creation_content, :map
|
||||||
|
|
||||||
embeds_one :power_level_content_override, PowerLevelContentOverride, primary_key: false do
|
embeds_one :power_level_content_override, PowerLevelContentOverride, primary_key: false do
|
||||||
field :ban, :integer
|
field :ban, :integer
|
||||||
|
@ -57,8 +59,7 @@ defmodule ArchitexWeb.Client.Request.CreateRoom do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: unimplemented:
|
# TODO: unimplemented: invite_3pid, initial_state, room_alias_name
|
||||||
# creation_content, initial_state, invite_3pid, initial_state
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def changeset(data, params) do
|
def changeset(data, params) do
|
||||||
|
@ -71,7 +72,8 @@ defmodule ArchitexWeb.Client.Request.CreateRoom do
|
||||||
:invite,
|
:invite,
|
||||||
:room_version,
|
:room_version,
|
||||||
:preset,
|
:preset,
|
||||||
:is_direct
|
:is_direct,
|
||||||
|
:creation_content
|
||||||
])
|
])
|
||||||
|> cast_embed(:power_level_content_override,
|
|> cast_embed(:power_level_content_override,
|
||||||
with: &power_level_content_override_changeset/2,
|
with: &power_level_content_override_changeset/2,
|
||||||
|
|
Loading…
Reference in a new issue