Add comment to restrictOldRoomPowerLevels

This commit is contained in:
Neil Alexander 2022-04-04 17:03:40 +01:00
parent e211836f5a
commit 95bb7a51c1
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
2 changed files with 10 additions and 11 deletions

View file

@ -143,14 +143,15 @@ func (r *Upgrader) getRoomPowerLevels(ctx context.Context, roomID string) (*goma
}
func (r *Upgrader) restrictOldRoomPowerLevels(ctx context.Context, evTime time.Time, userID, roomID string) *api.PerformError {
powerLevelContent, pErr := r.getRoomPowerLevels(ctx, roomID)
restrictedPowerLevelContent, pErr := r.getRoomPowerLevels(ctx, roomID)
if pErr != nil {
return pErr
}
restrictedPowerLevelContent := &gomatrixserverlib.PowerLevelContent{}
*restrictedPowerLevelContent = *powerLevelContent
// From: https://spec.matrix.org/v1.2/client-server-api/#server-behaviour-16
// If possible, the power levels in the old room should also be modified to
// prevent sending of events and inviting new users. For example, setting
// events_default and invite to the greater of 50 and users_default + 1.
restrictedDefaultPowerLevel := int64(50)
if restrictedPowerLevelContent.UsersDefault+1 > restrictedDefaultPowerLevel {
restrictedDefaultPowerLevel = restrictedPowerLevelContent.UsersDefault + 1
@ -159,8 +160,9 @@ func (r *Upgrader) restrictOldRoomPowerLevels(ctx context.Context, evTime time.T
restrictedPowerLevelContent.Invite = restrictedDefaultPowerLevel
restrictedPowerLevelsHeadered, resErr := r.makeHeaderedEvent(ctx, evTime, userID, roomID, fledglingEvent{
Type: gomatrixserverlib.MRoomPowerLevels,
Content: restrictedPowerLevelContent,
Type: gomatrixserverlib.MRoomPowerLevels,
StateKey: "",
Content: restrictedPowerLevelContent,
})
if resErr != nil {
if resErr.Code == api.PerformErrorNotAllowed {
@ -242,12 +244,12 @@ func (r *Upgrader) publishIfOldRoomWasPublic(ctx context.Context, roomID, newRoo
// if the old room is published (was public), publish the new room
if len(pubQueryRes.RoomIDs) == 1 {
publishNewRoom(ctx, r.URSAPI, roomID, newRoomID)
publishNewRoomAndUnpublishOldRoom(ctx, r.URSAPI, roomID, newRoomID)
}
return nil
}
func publishNewRoom(
func publishNewRoomAndUnpublishOldRoom(
ctx context.Context,
URSAPI api.RoomserverInternalAPI,
oldRoomID, newRoomID string,

View file

@ -680,6 +680,3 @@ remote user has push rules copied to upgraded room
Cannot send tombstone event that points to the same room
Room summary counts change when membership changes
/upgrade copies >100 power levels to the new room
/upgrade moves remote aliases to the new room
/upgrade preserves direct room state
Local and remote users' homeservers remove a room from their public directory on upgrade