Properly check power levels before allowing kick
This commit is contained in:
parent
2a0a3765fc
commit
2d231b7af1
|
@ -306,6 +306,20 @@ class MatrixClient(nio.AsyncClient):
|
||||||
return (await self.content_repository_config()).upload_size
|
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
|
@property
|
||||||
def all_rooms(self) -> Dict[str, nio.MatrixRoom]:
|
def all_rooms(self) -> Dict[str, nio.MatrixRoom]:
|
||||||
"""Return dict containing both our joined and invited rooms."""
|
"""Return dict containing both our joined and invited rooms."""
|
||||||
|
|
|
@ -57,7 +57,7 @@ HTileDelegate {
|
||||||
icon.name: "room-kick"
|
icon.name: "room-kick"
|
||||||
icon.color: theme.colors.negativeBackground
|
icon.color: theme.colors.negativeBackground
|
||||||
text: model.invited ? qsTr("Disinvite") : qsTr("Kick")
|
text: model.invited ? qsTr("Disinvite") : qsTr("Kick")
|
||||||
enabled: chat.roomInfo.can_kick
|
enabled: false
|
||||||
|
|
||||||
popup: "Popups/KickPopup.qml"
|
popup: "Popups/KickPopup.qml"
|
||||||
popupParent: chat
|
popupParent: chat
|
||||||
|
@ -68,6 +68,13 @@ HTileDelegate {
|
||||||
targetDisplayName: model.display_name,
|
targetDisplayName: model.display_name,
|
||||||
targetIsInvited: model.invited,
|
targetIsInvited: model.invited,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Component.onCompleted: py.callClientCoro(
|
||||||
|
chat.userId,
|
||||||
|
"can_kick",
|
||||||
|
[chat.roomId, model.id],
|
||||||
|
can => { enabled = can },
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user