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.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 =
|
||||||
|
|
|
@ -63,26 +63,49 @@ 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(
|
||||||
ban: ban_override,
|
room,
|
||||||
events: events_override,
|
%Account{localpart: localpart} = sender,
|
||||||
events_default: events_default_override,
|
%PowerLevelContentOverride{
|
||||||
invite: invite_override,
|
ban: ban_override,
|
||||||
kick: kick_override,
|
events: events_override,
|
||||||
redact: redact_override,
|
events_default: events_default_override,
|
||||||
state_default: state_default_override,
|
invite: invite_override,
|
||||||
users: users_override,
|
kick: kick_override,
|
||||||
users_default: users_default_override,
|
redact: redact_override,
|
||||||
notifications: notifications_override
|
state_default: state_default_override,
|
||||||
}) do
|
users: users_override,
|
||||||
|
users_default: users_default_override,
|
||||||
|
notifications: notifications_override
|
||||||
|
},
|
||||||
|
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
|
||||||
|
|
Loading…
Reference in a new issue