From 0a2d274824a3500fe29921196c3a44672532acba Mon Sep 17 00:00:00 2001 From: miruka Date: Sat, 27 Jun 2020 11:11:14 -0400 Subject: [PATCH] Add verified devices indicator to room header --- TODO.md | 2 +- src/backend/matrix_client.py | 13 ++++++++++--- src/backend/models/items.py | 9 +++++---- src/backend/nio_callbacks.py | 19 +++++++++++++++++++ src/gui/Pages/Chat/RoomHeader.qml | 30 ++++++++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 8 deletions(-) diff --git a/TODO.md b/TODO.md index 9afd76d5..ebf78914 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,6 @@ # TODO - issue templates -- ctrl-tab highlight ## Refactoring @@ -11,6 +10,7 @@ ## Issues +- Signing out leaves the account's rooms in the list - Need to unregister popups/menus when they are destroyed without being closed - Bottom focus line for an `HTextArea` inside a `ScrollView` is invisible, diff --git a/src/backend/matrix_client.py b/src/backend/matrix_client.py index 8dc5987e..d151f778 100644 --- a/src/backend/matrix_client.py +++ b/src/backend/matrix_client.py @@ -1412,6 +1412,11 @@ class MatrixClient(nio.AsyncClient): local_unreads = False local_highlights = False update_account_unread_counts = True + unverified_devices = ( + False + if isinstance(room, nio.MatrixInvitedRoom) else + self.room_contains_unverified(room.room_id) + ) else: last_event_date = registered.last_event_date typing_members = registered.typing_members @@ -1421,6 +1426,7 @@ class MatrixClient(nio.AsyncClient): registered.unreads != room.unread_notifications or registered.highlights != room.unread_highlights ) + unverified_devices = registered.unverified_devices room_item = Room( id = room.room_id, @@ -1442,9 +1448,10 @@ class MatrixClient(nio.AsyncClient): typing_members = typing_members, - encrypted = room.encrypted, - invite_required = room.join_rule == "invite", - guests_allowed = room.guest_access == "can_join", + encrypted = room.encrypted, + unverified_devices = unverified_devices, + invite_required = room.join_rule == "invite", + guests_allowed = room.guest_access == "can_join", can_invite = levels.can_user_invite(self.user), can_kick = levels.can_user_kick(self.user), diff --git a/src/backend/models/items.py b/src/backend/models/items.py index e68041ef..d06d47a6 100644 --- a/src/backend/models/items.py +++ b/src/backend/models/items.py @@ -68,10 +68,11 @@ class Room(ModelItem): typing_members: List[str] = field(default_factory=list) - federated: bool = True - encrypted: bool = False - invite_required: bool = True - guests_allowed: bool = True + federated: bool = True + encrypted: bool = False + unverified_devices: bool = False + invite_required: bool = True + guests_allowed: bool = True can_invite: bool = False can_kick: bool = False diff --git a/src/backend/nio_callbacks.py b/src/backend/nio_callbacks.py index 0f697232..ff3c66b4 100644 --- a/src/backend/nio_callbacks.py +++ b/src/backend/nio_callbacks.py @@ -105,6 +105,25 @@ class NioCallbacks: account.first_sync_done = True + async def onKeysQueryResponse(self, resp: nio.KeysQueryResponse) -> None: + refresh_rooms = {} + + for user_id in resp.changed: + for room in self.client.rooms.values(): + if user_id in room.users: + refresh_rooms[room.room_id] = room + + for room_id, room in refresh_rooms.items(): + room_item = self.models[self.user_id, "rooms"].get(room_id) + + if room_item: + room_item.unverified_devices = \ + self.client.room_contains_unverified(room_id) + else: + await self.client.register_nio_room(room) + + + # Room events, invite events and misc events callbacks async def onRoomMessageText( diff --git a/src/gui/Pages/Chat/RoomHeader.qml b/src/gui/Pages/Chat/RoomHeader.qml index ec4a7a82..1807ade1 100644 --- a/src/gui/Pages/Chat/RoomHeader.qml +++ b/src/gui/Pages/Chat/RoomHeader.qml @@ -122,6 +122,36 @@ Rectangle { visible: center } + HButton { + id: encryptionStatusButton + padded: false + visible: Layout.preferredWidth > 0 + backgroundColor: "transparent" + + icon.name: + chat.roomInfo.unverified_devices ? + "device-unset" : + "device-verified" + + icon.color: + chat.roomInfo.unverified_devices ? + theme.colors.warningText : + theme.colors.positiveText + + toolTip.text: + chat.roomInfo.unverified_devices ? + qsTr("Some members in this encrypted room have " + + "unverified devices") : + qsTr("All members in this encrypted room are verified") + + onClicked: toolTip.instantShow() + + Layout.preferredWidth: chat.roomInfo.encrypted ? avatar.width : 0 + Layout.fillHeight: true + + Behavior on Layout.preferredWidth { HNumberAnimation {} } + } + HButton { id: goToRoomPaneButton padded: false