From 9bad584931a03717f71e96900202acac43d2a62f Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Fri, 13 Aug 2021 23:58:26 +0200 Subject: [PATCH] Show verification status in memberlist --- resources/qml/RoomMembers.qml | 42 ++++++++++++++++++++++++---- resources/qml/Root.qml | 4 +-- resources/qml/TopBar.qml | 2 +- src/Cache.cpp | 2 -- src/MemberList.cpp | 12 ++++++++ src/MemberList.h | 1 + src/timeline/TimelineViewManager.cpp | 8 ++++-- src/timeline/TimelineViewManager.h | 4 +-- 8 files changed, 59 insertions(+), 16 deletions(-) diff --git a/resources/qml/RoomMembers.qml b/resources/qml/RoomMembers.qml index 447e6fd1..8e44855c 100644 --- a/resources/qml/RoomMembers.qml +++ b/resources/qml/RoomMembers.qml @@ -13,6 +13,7 @@ ApplicationWindow { id: roomMembersRoot property MemberList members + property Room room title: qsTr("Members of %1").arg(members.roomName) height: 650 @@ -83,9 +84,14 @@ ApplicationWindow { } delegate: RowLayout { + id: del + + width: ListView.view.width spacing: Nheko.paddingMedium Avatar { + id: avatar + width: Nheko.avatarSize height: Nheko.avatarSize userid: model.mxid @@ -97,16 +103,18 @@ ApplicationWindow { ColumnLayout { spacing: Nheko.paddingSmall - Label { - text: model.displayName + ElidedLabel { + fullText: model.displayName color: TimelineManager.userColor(model ? model.mxid : "", Nheko.colors.window) - font.pointSize: fontMetrics.font.pointSize + font.pixelSize: fontMetrics.font.pixelSize + elideWidth: del.width - Nheko.paddingMedium * 2 - avatar.width - encryptInd.width } - Label { - text: model.mxid + ElidedLabel { + fullText: model.mxid color: Nheko.colors.buttonText - font.pointSize: fontMetrics.font.pointSize * 0.9 + font.pixelSize: Math.ceil(fontMetrics.font.pixelSize * 0.9) + elideWidth: del.width - Nheko.paddingMedium * 2 - avatar.width - encryptInd.width } Item { @@ -116,6 +124,28 @@ ApplicationWindow { } + EncryptionIndicator { + id: encryptInd + + Layout.alignment: Qt.AlignRight + visible: room.isEncrypted + encrypted: room.isEncrypted + trust: encrypted ? model.trustlevel : Crypto.Unverified + ToolTip.text: { + if (!encrypted) + return qsTr("This room is not encrypted!"); + + switch (trust) { + case Crypto.Verified: + return qsTr("This user is verified."); + case Crypto.TOFU: + return qsTr("This user isn't verified, but is still using the same master key from the first time you met."); + default: + return qsTr("This user has unverified devices!"); + } + } + } + } footer: Item { diff --git a/resources/qml/Root.qml b/resources/qml/Root.qml index b229acda..79f12bbf 100644 --- a/resources/qml/Root.qml +++ b/resources/qml/Root.qml @@ -153,10 +153,10 @@ Page { packSet.show(); } - function onOpenRoomMembersDialog(members) { + function onOpenRoomMembersDialog(members, room) { var membersDialog = roomMembersComponent.createObject(timelineRoot, { "members": members, - "roomName": Rooms.currentRoom.roomName + "room": room }); membersDialog.show(); } diff --git a/resources/qml/TopBar.qml b/resources/qml/TopBar.qml index 0faaea9c..7f67c028 100644 --- a/resources/qml/TopBar.qml +++ b/resources/qml/TopBar.qml @@ -140,7 +140,7 @@ Rectangle { Platform.MenuItem { text: qsTr("Members") - onTriggered: TimelineManager.openRoomMembers(room.roomId) + onTriggered: TimelineManager.openRoomMembers(room) } Platform.MenuItem { diff --git a/src/Cache.cpp b/src/Cache.cpp index 5edfaf09..ea034dd0 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -3584,8 +3584,6 @@ Cache::roomMembers(const std::string &room_id) crypto::Trust Cache::roomVerificationStatus(const std::string &room_id) { - std::string_view keys; - crypto::Trust trust = crypto::Verified; try { diff --git a/src/MemberList.cpp b/src/MemberList.cpp index 196647fe..0c0f0cdd 100644 --- a/src/MemberList.cpp +++ b/src/MemberList.cpp @@ -53,6 +53,7 @@ MemberList::roleNames() const {Mxid, "mxid"}, {DisplayName, "displayName"}, {AvatarUrl, "avatarUrl"}, + {Trustlevel, "trustlevel"}, }; } @@ -69,6 +70,17 @@ MemberList::data(const QModelIndex &index, int role) const return m_memberList[index.row()].first.display_name; case AvatarUrl: return m_memberList[index.row()].second; + case Trustlevel: { + auto stat = + cache::verificationStatus(m_memberList[index.row()].first.user_id.toStdString()); + + if (!stat) + return crypto::Unverified; + if (stat->unverified_device_count) + return crypto::Unverified; + else + return stat->user_verified; + } default: return {}; } diff --git a/src/MemberList.h b/src/MemberList.h index e6522694..cffcd83d 100644 --- a/src/MemberList.h +++ b/src/MemberList.h @@ -25,6 +25,7 @@ public: Mxid, DisplayName, AvatarUrl, + Trustlevel, }; MemberList(const QString &room_id, QObject *parent = nullptr); diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp index b23ed278..906e328f 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp @@ -375,10 +375,12 @@ TimelineViewManager::TimelineViewManager(CallManager *callManager, ChatPage *par } void -TimelineViewManager::openRoomMembers(QString room_id) +TimelineViewManager::openRoomMembers(TimelineModel *room) { - MemberList *memberList = new MemberList(room_id, this); - emit openRoomMembersDialog(memberList); + if (!room) + return; + MemberList *memberList = new MemberList(room->roomId(), this); + emit openRoomMembersDialog(memberList, room); } void diff --git a/src/timeline/TimelineViewManager.h b/src/timeline/TimelineViewManager.h index 54e3a935..4dd5e996 100644 --- a/src/timeline/TimelineViewManager.h +++ b/src/timeline/TimelineViewManager.h @@ -66,7 +66,7 @@ public: Q_INVOKABLE QString userPresence(QString id) const; Q_INVOKABLE QString userStatus(QString id) const; - Q_INVOKABLE void openRoomMembers(QString room_id); + Q_INVOKABLE void openRoomMembers(TimelineModel *room); Q_INVOKABLE void openRoomSettings(QString room_id); Q_INVOKABLE void openInviteUsers(QString roomId); Q_INVOKABLE void openGlobalUserProfile(QString userId); @@ -92,7 +92,7 @@ signals: void focusChanged(); void focusInput(); void openImageOverlayInternalCb(QString eventId, QImage img); - void openRoomMembersDialog(MemberList *members); + void openRoomMembersDialog(MemberList *members, TimelineModel *room); void openRoomSettingsDialog(RoomSettings *settings); void openInviteUsersDialog(InviteesModel *invitees); void openProfile(UserProfile *profile);