|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # 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 |
15 | 15 |
|
16 | 16 | from synapse import event_auth |
17 | 17 | from synapse.api.constants import ( |
@@ -122,17 +122,15 @@ async def get_user_which_could_invite( |
122 | 122 |
|
123 | 123 | # Find the user with the highest power level. |
124 | 124 | 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 | + ) |
132 | 130 |
|
133 | 131 | # Return the chosen user. |
134 | 132 | if chosen_user: |
135 | | - return chosen_user[0] |
| 133 | + return chosen_user |
136 | 134 |
|
137 | 135 | # TODO What to do if no user is found? |
138 | 136 | return None |
|
0 commit comments