diff options
author | Patrick Cloke <clokep@users.noreply.github.com> | 2021-10-13 07:24:07 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-13 07:24:07 -0400 |
commit | 1f9d0b8a7a6a777d59fe3217724f3e2ddb94a9b2 (patch) | |
tree | 194112442fecf38e0b54cc6844c93f64c2dfefb6 /synapse/handlers | |
parent | Port the Password Auth Providers module interface to the new generic interfac... (diff) | |
download | synapse-1f9d0b8a7a6a777d59fe3217724f3e2ddb94a9b2.tar.xz |
Add type hints to synapse.events.*. (#11066)
Except `synapse/events/__init__.py`, which will be done in a follow-up.
Diffstat (limited to 'synapse/handlers')
-rw-r--r-- | synapse/handlers/room.py | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py index 7072bca1fc..6f39e9446f 100644 --- a/synapse/handlers/room.py +++ b/synapse/handlers/room.py @@ -465,17 +465,35 @@ class RoomCreationHandler: # the room has been created # Calculate the minimum power level needed to clone the room event_power_levels = power_levels.get("events", {}) + if not isinstance(event_power_levels, dict): + event_power_levels = {} state_default = power_levels.get("state_default", 50) + try: + state_default_int = int(state_default) # type: ignore[arg-type] + except (TypeError, ValueError): + state_default_int = 50 ban = power_levels.get("ban", 50) - needed_power_level = max(state_default, ban, max(event_power_levels.values())) + try: + ban = int(ban) # type: ignore[arg-type] + except (TypeError, ValueError): + ban = 50 + needed_power_level = max( + state_default_int, ban, max(event_power_levels.values()) + ) # Get the user's current power level, this matches the logic in get_user_power_level, # but without the entire state map. user_power_levels = power_levels.setdefault("users", {}) + if not isinstance(user_power_levels, dict): + user_power_levels = {} users_default = power_levels.get("users_default", 0) current_power_level = user_power_levels.get(user_id, users_default) + try: + current_power_level_int = int(current_power_level) # type: ignore[arg-type] + except (TypeError, ValueError): + current_power_level_int = 0 # Raise the requester's power level in the new room if necessary - if current_power_level < needed_power_level: + if current_power_level_int < needed_power_level: user_power_levels[user_id] = needed_power_level await self._send_events_for_new_room( |