event: fix 32-bit compatibility

This commit is contained in:
Tulir Asokan 2025-10-24 12:56:53 +03:00
commit ee1e05c3e8

View file

@ -132,14 +132,18 @@ func (pl *PowerLevelsEventContent) GetUserLevel(userID id.UserID) int {
return level
}
const maxPL = 1<<53 - 1
func (pl *PowerLevelsEventContent) SetUserLevel(userID id.UserID, level int) {
pl.usersLock.Lock()
defer pl.usersLock.Unlock()
if pl.isCreator(userID) {
return
}
if level == math.MaxInt {
level = 1<<53 - 1
if level == math.MaxInt && maxPL < math.MaxInt {
// Hack to avoid breaking on 32-bit systems (they're only slightly supported)
x := int64(maxPL)
level = int(x)
}
if level == pl.UsersDefault {
delete(pl.Users, userID)