Give invitees the same power level as the creator during client room
creation
This commit is contained in:
parent
8dfd770fd0
commit
56be8ba301
2 changed files with 45 additions and 18 deletions
|
@ -456,7 +456,13 @@ defmodule Architex.RoomServer do
|
|||
([
|
||||
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)
|
||||
Event.PowerLevels.create_room_new(
|
||||
room,
|
||||
account,
|
||||
power_level_content_override,
|
||||
invite,
|
||||
preset
|
||||
)
|
||||
] ++
|
||||
room_creation_preset(account, preset, room) ++
|
||||
[
|
||||
|
@ -500,8 +506,6 @@ defmodule Architex.RoomServer do
|
|||
end
|
||||
|
||||
# Get the events for room creation as dictated by the given preset.
|
||||
# TODO: trusted_private_chat:
|
||||
# All invitees are given the same power level as the room creator.
|
||||
@spec room_creation_preset(Account.t(), String.t() | nil, Room.t()) :: [%Event{}]
|
||||
defp room_creation_preset(account, nil, %Room{visibility: visibility} = room) do
|
||||
preset =
|
||||
|
|
|
@ -63,26 +63,49 @@ defmodule Architex.Event.PowerLevels do
|
|||
@users_default 0
|
||||
@notifications_room 50
|
||||
|
||||
@spec create_room_new(Room.t(), Account.t(), CreateRoom.plco_t()) :: %Event{}
|
||||
def create_room_new(room, sender, nil) do
|
||||
create_room_new(room, sender, %PowerLevelContentOverride{})
|
||||
@spec create_room_new(
|
||||
Room.t(),
|
||||
Account.t(),
|
||||
CreateRoom.plco_t(),
|
||||
[String.t()] | nil,
|
||||
String.t() | nil
|
||||
) :: %Event{}
|
||||
def create_room_new(room, sender, nil, invite_ids, preset) do
|
||||
create_room_new(room, sender, %PowerLevelContentOverride{}, invite_ids, preset)
|
||||
end
|
||||
|
||||
def create_room_new(room, %Account{localpart: localpart} = sender, %PowerLevelContentOverride{
|
||||
ban: ban_override,
|
||||
events: events_override,
|
||||
events_default: events_default_override,
|
||||
invite: invite_override,
|
||||
kick: kick_override,
|
||||
redact: redact_override,
|
||||
state_default: state_default_override,
|
||||
users: users_override,
|
||||
users_default: users_default_override,
|
||||
notifications: notifications_override
|
||||
}) do
|
||||
def create_room_new(
|
||||
room,
|
||||
%Account{localpart: localpart} = sender,
|
||||
%PowerLevelContentOverride{
|
||||
ban: ban_override,
|
||||
events: events_override,
|
||||
events_default: events_default_override,
|
||||
invite: invite_override,
|
||||
kick: kick_override,
|
||||
redact: redact_override,
|
||||
state_default: state_default_override,
|
||||
users: users_override,
|
||||
users_default: users_default_override,
|
||||
notifications: notifications_override
|
||||
},
|
||||
invite_ids,
|
||||
preset
|
||||
) do
|
||||
mxid = Architex.get_mxid(localpart)
|
||||
users = %{mxid => @creator}
|
||||
users = if users_override, do: Map.merge(users, users_override), else: users
|
||||
creator_pl = users[mxid]
|
||||
|
||||
# Give each invitee the same power level as the creator.
|
||||
# This overrides the content override, but the spec is not clear on this.
|
||||
users =
|
||||
if preset == "trusted_private_chat" and invite_ids do
|
||||
invite_users_pls = Enum.into(invite_ids, %{}, &{&1, creator_pl})
|
||||
Map.merge(users, invite_users_pls)
|
||||
else
|
||||
users
|
||||
end
|
||||
|
||||
notifications =
|
||||
case notifications_override do
|
||||
|
|
Loading…
Reference in a new issue