Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit fbe0038

Browse files
committed
Simplify logic to find user with maximum PL.
1 parent 9f497a0 commit fbe0038

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

synapse/handlers/event_auth.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from typing import TYPE_CHECKING, Collection, List, Optional, Tuple, Union
14+
from typing import TYPE_CHECKING, Collection, List, Optional, Union
1515

1616
from synapse import event_auth
1717
from synapse.api.constants import (
@@ -122,17 +122,15 @@ async def get_user_which_could_invite(
122122

123123
# Find the user with the highest power level.
124124
users_in_room = await self._store.get_users_in_room(room_id)
125-
# A tuple of the chosen user's MXID and power level.
126-
chosen_user: Optional[Tuple[str, int]] = None
127-
for user in users_in_room:
128-
user_level = users.get(user, users_default_level)
129-
if user_level >= invite_level:
130-
if chosen_user is None or user_level >= chosen_user[1]:
131-
chosen_user = (user, user_level)
125+
chosen_user = max(
126+
users_in_room,
127+
key=lambda user: users.get(user, users_default_level),
128+
default=None,
129+
)
132130

133131
# Return the chosen user.
134132
if chosen_user:
135-
return chosen_user[0]
133+
return chosen_user
136134

137135
# TODO What to do if no user is found?
138136
return None

0 commit comments

Comments
 (0)