Implement is_direct option for client room creation
This commit is contained in:
parent
8ab147190e
commit
d23a42e29c
4 changed files with 20 additions and 15 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: 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
|
- 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.
|
||||||
|
|
|
@ -448,9 +448,9 @@ defmodule Architex.RoomServer do
|
||||||
name: name,
|
name: name,
|
||||||
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
|
||||||
}) do
|
}) do
|
||||||
|
|
||||||
events =
|
events =
|
||||||
([
|
([
|
||||||
Event.CreateRoom.new(room, account, room_version),
|
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(name, do: Event.Name.new(room, account, name)),
|
||||||
if(topic, do: Event.Topic.new(room, account, topic))
|
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)
|
|> Enum.reject(&Kernel.is_nil/1)
|
||||||
|
|
||||||
fn ->
|
fn ->
|
||||||
|
@ -528,11 +528,12 @@ defmodule Architex.RoomServer do
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the events for room creation for inviting other users.
|
# Get the events for room creation for inviting other users.
|
||||||
@spec room_creation_invite_events(Account.t(), [String.t()] | nil, Room.t()) :: [%Event{}]
|
@spec room_creation_invite_events(Account.t(), [String.t()] | nil, Room.t(), boolean() | nil) ::
|
||||||
defp room_creation_invite_events(_, nil, _), do: []
|
[%Event{}]
|
||||||
|
defp room_creation_invite_events(_, nil, _, _), do: []
|
||||||
|
|
||||||
defp room_creation_invite_events(account, invite_user_ids, room) do
|
defp room_creation_invite_events(account, invite_user_ids, room, is_direct) do
|
||||||
Enum.map(invite_user_ids, &Event.Invite.new(room, account, &1))
|
Enum.map(invite_user_ids, &Event.Invite.new(room, account, &1, is_direct))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Finalize the event struct and insert it into the room's state using state resolution.
|
# Finalize the event struct and insert it into the room's state using state resolution.
|
||||||
|
|
|
@ -180,15 +180,16 @@ end
|
||||||
defmodule Architex.Event.Invite do
|
defmodule Architex.Event.Invite do
|
||||||
alias Architex.{Event, Account, Room}
|
alias Architex.{Event, Account, Room}
|
||||||
|
|
||||||
@spec new(Room.t(), Account.t(), String.t()) :: %Event{}
|
@spec new(Room.t(), Account.t(), String.t(), boolean() | nil) :: %Event{}
|
||||||
def new(room, sender, user_id) do
|
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{
|
||||||
Event.new(room, sender)
|
Event.new(room, sender)
|
||||||
| type: "m.room.member",
|
| type: "m.room.member",
|
||||||
state_key: user_id,
|
state_key: user_id,
|
||||||
content: %{
|
content: content
|
||||||
"membership" => "invite"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,6 +9,7 @@ defmodule ArchitexWeb.Client.Request.CreateRoom do
|
||||||
invite: list(String.t()) | nil,
|
invite: list(String.t()) | nil,
|
||||||
room_version: String.t() | nil,
|
room_version: String.t() | nil,
|
||||||
preset: String.t() | nil,
|
preset: String.t() | nil,
|
||||||
|
is_direct: boolean() | nil,
|
||||||
power_level_content_override: plco_t() | nil
|
power_level_content_override: plco_t() | nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +39,7 @@ defmodule ArchitexWeb.Client.Request.CreateRoom do
|
||||||
field :invite, {:array, :string}
|
field :invite, {:array, :string}
|
||||||
field :room_version, :string
|
field :room_version, :string
|
||||||
field :preset, :string
|
field :preset, :string
|
||||||
|
field :is_direct, :boolean
|
||||||
|
|
||||||
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
|
||||||
|
@ -56,7 +58,7 @@ defmodule ArchitexWeb.Client.Request.CreateRoom do
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: unimplemented:
|
# TODO: unimplemented:
|
||||||
# creation_content, initial_state, invite_3pid, initial_state, is_direct
|
# creation_content, initial_state, invite_3pid, initial_state
|
||||||
end
|
end
|
||||||
|
|
||||||
def changeset(data, params) do
|
def changeset(data, params) do
|
||||||
|
@ -68,7 +70,8 @@ defmodule ArchitexWeb.Client.Request.CreateRoom do
|
||||||
:topic,
|
:topic,
|
||||||
:invite,
|
:invite,
|
||||||
:room_version,
|
:room_version,
|
||||||
:preset
|
:preset,
|
||||||
|
:is_direct
|
||||||
])
|
])
|
||||||
|> 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