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
|
||||
- POST /_matrix/client/r0/login: Only with password 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
|
||||
- POST /_matrix/client/r0/rooms/{roomId}/invite
|
||||
- POST /_matrix/client/r0/rooms/{roomId}/join: Except with third party invite.
|
||||
|
|
|
@ -449,11 +449,12 @@ defmodule Architex.RoomServer do
|
|||
topic: topic,
|
||||
invite: invite,
|
||||
power_level_content_override: power_level_content_override,
|
||||
is_direct: is_direct
|
||||
is_direct: is_direct,
|
||||
creation_content: creation_content
|
||||
}) do
|
||||
events =
|
||||
([
|
||||
Event.CreateRoom.new(room, account, room_version),
|
||||
Event.CreateRoom.new(room, account, room_version, creation_content),
|
||||
Event.Join.new(room, account),
|
||||
Event.PowerLevels.create_room_new(room, account, power_level_content_override)
|
||||
] ++
|
||||
|
|
|
@ -19,18 +19,31 @@ end
|
|||
defmodule Architex.Event.CreateRoom do
|
||||
alias Architex.{Event, Account, Room}
|
||||
|
||||
@spec new(Room.t(), Account.t(), String.t()) :: %Event{}
|
||||
def new(room, %Account{localpart: localpart} = creator, room_version) do
|
||||
@clobber_content_keys ["creator", "room_version"]
|
||||
|
||||
@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)
|
||||
|
||||
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.new(room, creator)
|
||||
| type: "m.room.create",
|
||||
state_key: "",
|
||||
content: %{
|
||||
"creator" => mxid,
|
||||
"room_version" => room_version || Architex.default_room_version()
|
||||
}
|
||||
content: content
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,6 +10,7 @@ defmodule ArchitexWeb.Client.Request.CreateRoom do
|
|||
room_version: String.t() | nil,
|
||||
preset: String.t() | nil,
|
||||
is_direct: boolean() | nil,
|
||||
creation_content: %{optional(String.t()) => any()} | nil,
|
||||
power_level_content_override: plco_t() | nil
|
||||
}
|
||||
|
||||
|
@ -40,6 +41,7 @@ defmodule ArchitexWeb.Client.Request.CreateRoom do
|
|||
field :room_version, :string
|
||||
field :preset, :string
|
||||
field :is_direct, :boolean
|
||||
field :creation_content, :map
|
||||
|
||||
embeds_one :power_level_content_override, PowerLevelContentOverride, primary_key: false do
|
||||
field :ban, :integer
|
||||
|
@ -57,8 +59,7 @@ defmodule ArchitexWeb.Client.Request.CreateRoom do
|
|||
end
|
||||
end
|
||||
|
||||
# TODO: unimplemented:
|
||||
# creation_content, initial_state, invite_3pid, initial_state
|
||||
# TODO: unimplemented: invite_3pid, initial_state, room_alias_name
|
||||
end
|
||||
|
||||
def changeset(data, params) do
|
||||
|
@ -71,7 +72,8 @@ defmodule ArchitexWeb.Client.Request.CreateRoom do
|
|||
:invite,
|
||||
:room_version,
|
||||
:preset,
|
||||
:is_direct
|
||||
:is_direct,
|
||||
:creation_content
|
||||
])
|
||||
|> cast_embed(:power_level_content_override,
|
||||
with: &power_level_content_override_changeset/2,
|
||||
|
|
Loading…
Reference in a new issue