Give invitees the same power level as the creator during client room

creation
This commit is contained in:
Pim Kunis 2021-09-11 22:31:00 +02:00
parent 8dfd770fd0
commit 56be8ba301
2 changed files with 45 additions and 18 deletions

View file

@ -456,7 +456,13 @@ defmodule Architex.RoomServer do
([ ([
Event.CreateRoom.new(room, account, room_version, creation_content), 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,
invite,
preset
)
] ++ ] ++
room_creation_preset(account, preset, room) ++ room_creation_preset(account, preset, room) ++
[ [
@ -500,8 +506,6 @@ defmodule Architex.RoomServer do
end end
# Get the events for room creation as dictated by the given preset. # 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{}] @spec room_creation_preset(Account.t(), String.t() | nil, Room.t()) :: [%Event{}]
defp room_creation_preset(account, nil, %Room{visibility: visibility} = room) do defp room_creation_preset(account, nil, %Room{visibility: visibility} = room) do
preset = preset =

View file

@ -63,12 +63,21 @@ defmodule Architex.Event.PowerLevels do
@users_default 0 @users_default 0
@notifications_room 50 @notifications_room 50
@spec create_room_new(Room.t(), Account.t(), CreateRoom.plco_t()) :: %Event{} @spec create_room_new(
def create_room_new(room, sender, nil) do Room.t(),
create_room_new(room, sender, %PowerLevelContentOverride{}) 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 end
def create_room_new(room, %Account{localpart: localpart} = sender, %PowerLevelContentOverride{ def create_room_new(
room,
%Account{localpart: localpart} = sender,
%PowerLevelContentOverride{
ban: ban_override, ban: ban_override,
events: events_override, events: events_override,
events_default: events_default_override, events_default: events_default_override,
@ -79,10 +88,24 @@ defmodule Architex.Event.PowerLevels do
users: users_override, users: users_override,
users_default: users_default_override, users_default: users_default_override,
notifications: notifications_override notifications: notifications_override
}) do },
invite_ids,
preset
) do
mxid = Architex.get_mxid(localpart) mxid = Architex.get_mxid(localpart)
users = %{mxid => @creator} users = %{mxid => @creator}
users = if users_override, do: Map.merge(users, users_override), else: users 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 = notifications =
case notifications_override do case notifications_override do