Implement is_direct option for client room creation

This commit is contained in:
Pim Kunis 2021-09-11 17:38:25 +02:00
parent 8ab147190e
commit d23a42e29c
4 changed files with 20 additions and 15 deletions

View file

@ -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: Only with optional parameters name, topic, preset and invite.
- POST /_matrix/client/r0/createRoom: Except creation_content, initial_state, invite_3pid and initial_state.
- 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.

View file

@ -448,9 +448,9 @@ defmodule Architex.RoomServer do
name: name,
topic: topic,
invite: invite,
power_level_content_override: power_level_content_override
power_level_content_override: power_level_content_override,
is_direct: is_direct
}) do
events =
([
Event.CreateRoom.new(room, account, room_version),
@ -461,7 +461,7 @@ defmodule Architex.RoomServer do
[
if(name, do: Event.Name.new(room, account, name)),
if(topic, do: Event.Topic.new(room, account, topic))
] ++ room_creation_invite_events(account, invite, room))
] ++ room_creation_invite_events(account, invite, room, is_direct))
|> Enum.reject(&Kernel.is_nil/1)
fn ->
@ -528,11 +528,12 @@ defmodule Architex.RoomServer do
end
# Get the events for room creation for inviting other users.
@spec room_creation_invite_events(Account.t(), [String.t()] | nil, Room.t()) :: [%Event{}]
defp room_creation_invite_events(_, nil, _), do: []
@spec room_creation_invite_events(Account.t(), [String.t()] | nil, Room.t(), boolean() | nil) ::
[%Event{}]
defp room_creation_invite_events(_, nil, _, _), do: []
defp room_creation_invite_events(account, invite_user_ids, room) do
Enum.map(invite_user_ids, &Event.Invite.new(room, account, &1))
defp room_creation_invite_events(account, invite_user_ids, room, is_direct) do
Enum.map(invite_user_ids, &Event.Invite.new(room, account, &1, is_direct))
end
# Finalize the event struct and insert it into the room's state using state resolution.

View file

@ -180,15 +180,16 @@ end
defmodule Architex.Event.Invite do
alias Architex.{Event, Account, Room}
@spec new(Room.t(), Account.t(), String.t()) :: %Event{}
def new(room, sender, user_id) do
@spec new(Room.t(), Account.t(), String.t(), boolean() | nil) :: %Event{}
def new(room, sender, user_id, is_direct \\ nil) do
content = %{"membership" => "invite"}
content = if is_direct != nil, do: Map.put(content, "is_direct", is_direct), else: content
%Event{
Event.new(room, sender)
| type: "m.room.member",
state_key: user_id,
content: %{
"membership" => "invite"
}
content: content
}
end
end

View file

@ -9,6 +9,7 @@ defmodule ArchitexWeb.Client.Request.CreateRoom do
invite: list(String.t()) | nil,
room_version: String.t() | nil,
preset: String.t() | nil,
is_direct: boolean() | nil,
power_level_content_override: plco_t() | nil
}
@ -38,6 +39,7 @@ defmodule ArchitexWeb.Client.Request.CreateRoom do
field :invite, {:array, :string}
field :room_version, :string
field :preset, :string
field :is_direct, :boolean
embeds_one :power_level_content_override, PowerLevelContentOverride, primary_key: false do
field :ban, :integer
@ -56,7 +58,7 @@ defmodule ArchitexWeb.Client.Request.CreateRoom do
end
# TODO: unimplemented:
# creation_content, initial_state, invite_3pid, initial_state, is_direct
# creation_content, initial_state, invite_3pid, initial_state
end
def changeset(data, params) do
@ -68,7 +70,8 @@ defmodule ArchitexWeb.Client.Request.CreateRoom do
:topic,
:invite,
:room_version,
:preset
:preset,
:is_direct
])
|> cast_embed(:power_level_content_override,
with: &power_level_content_override_changeset/2,