Properly check power levels before allowing kick

This commit is contained in:
miruka 2020-04-19 16:50:19 -04:00
parent 2a0a3765fc
commit 2d231b7af1
2 changed files with 22 additions and 1 deletions

View File

@ -306,6 +306,20 @@ class MatrixClient(nio.AsyncClient):
return (await self.content_repository_config()).upload_size
async def can_kick(self, room_id: str, target_user_id: str) -> bool:
"""Return whether we can kick a certain user in a room."""
levels = self.all_rooms[room_id].power_levels
return levels.can_user_kick(self.user_id, target_user_id)
async def can_ban(self, room_id: str, target_user_id: str) -> bool:
"""Return whether we can ban/unbun a certain user in a room."""
levels = self.all_rooms[room_id].power_levels
return levels.can_user_ban(self.user_id, target_user_id)
@property
def all_rooms(self) -> Dict[str, nio.MatrixRoom]:
"""Return dict containing both our joined and invited rooms."""

View File

@ -57,7 +57,7 @@ HTileDelegate {
icon.name: "room-kick"
icon.color: theme.colors.negativeBackground
text: model.invited ? qsTr("Disinvite") : qsTr("Kick")
enabled: chat.roomInfo.can_kick
enabled: false
popup: "Popups/KickPopup.qml"
popupParent: chat
@ -68,6 +68,13 @@ HTileDelegate {
targetDisplayName: model.display_name,
targetIsInvited: model.invited,
})
Component.onCompleted: py.callClientCoro(
chat.userId,
"can_kick",
[chat.roomId, model.id],
can => { enabled = can },
)
}
}