Skip to content
Snippets Groups Projects
Unverified Commit 8e2f1e9d authored by Nicolas Werner's avatar Nicolas Werner Committed by GitHub
Browse files

Merge pull request #416 from LorenDB/jdenticon

Add jdenticon support
parents 61f57b0e b9255803
No related branches found
No related tags found
No related merge requests found
Pipeline #1787 passed
Showing
with 112 additions and 12 deletions
...@@ -345,6 +345,7 @@ set(SRC_FILES ...@@ -345,6 +345,7 @@ set(SRC_FILES
src/DeviceVerificationFlow.cpp src/DeviceVerificationFlow.cpp
src/EventAccessors.cpp src/EventAccessors.cpp
src/InviteesModel.cpp src/InviteesModel.cpp
src/JdenticonProvider.cpp
src/Logging.cpp src/Logging.cpp
src/LoginPage.cpp src/LoginPage.cpp
src/MainWindow.cpp src/MainWindow.cpp
...@@ -557,6 +558,7 @@ qt5_wrap_cpp(MOC_HEADERS ...@@ -557,6 +558,7 @@ qt5_wrap_cpp(MOC_HEADERS
src/DeviceVerificationFlow.h src/DeviceVerificationFlow.h
src/ImagePackListModel.h src/ImagePackListModel.h
src/InviteesModel.h src/InviteesModel.h
src/JdenticonProvider.h
src/LoginPage.h src/LoginPage.h
src/MainWindow.h src/MainWindow.h
src/MemberList.h src/MemberList.h
......
...@@ -12,6 +12,7 @@ Rectangle { ...@@ -12,6 +12,7 @@ Rectangle {
property string url property string url
property string userid property string userid
property string roomid
property string displayName property string displayName
property alias textColor: label.color property alias textColor: label.color
property bool crop: true property bool crop: true
...@@ -35,10 +36,28 @@ Rectangle { ...@@ -35,10 +36,28 @@ Rectangle {
font.pixelSize: avatar.height / 2 font.pixelSize: avatar.height / 2
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
visible: img.status != Image.Ready visible: img.status != Image.Ready && !Settings.useIdenticon
color: Nheko.colors.text color: Nheko.colors.text
} }
Image {
id: identicon
anchors.fill: parent
visible: Settings.useIdenticon && img.status != Image.Ready
source: Settings.useIdenticon ? ("image://jdenticon/" + (userid !== "" ? userid : roomid) + "?radius=" + (Settings.avatarCircles ? 100 : 25)) : ""
MouseArea {
anchors.fill: parent
Ripple {
rippleTarget: parent
color: Qt.rgba(Nheko.colors.alternateBase.r, Nheko.colors.alternateBase.g, Nheko.colors.alternateBase.b, 0.5)
}
}
}
Image { Image {
id: img id: img
......
...@@ -130,6 +130,7 @@ Page { ...@@ -130,6 +130,7 @@ Page {
else else
return "image://colorimage/" + model.avatarUrl + "?" + communityItem.unimportantText; return "image://colorimage/" + model.avatarUrl + "?" + communityItem.unimportantText;
} }
roomid: model.id
displayName: model.displayName displayName: model.displayName
color: communityItem.background color: communityItem.background
} }
......
...@@ -139,6 +139,7 @@ Popup { ...@@ -139,6 +139,7 @@ Popup {
height: popup.avatarHeight height: popup.avatarHeight
width: popup.avatarWidth width: popup.avatarWidth
displayName: model.displayName displayName: model.displayName
userid: model.userid
url: model.avatarUrl.replace("mxc://", "image://MxcImage/") url: model.avatarUrl.replace("mxc://", "image://MxcImage/")
onClicked: popup.completionClicked(completer.completionAt(model.index)) onClicked: popup.completionClicked(completer.completionAt(model.index))
} }
...@@ -194,6 +195,7 @@ Popup { ...@@ -194,6 +195,7 @@ Popup {
height: popup.avatarHeight height: popup.avatarHeight
width: popup.avatarWidth width: popup.avatarWidth
displayName: model.roomName displayName: model.roomName
roomid: model.roomid
url: model.avatarUrl.replace("mxc://", "image://MxcImage/") url: model.avatarUrl.replace("mxc://", "image://MxcImage/")
onClicked: { onClicked: {
popup.completionClicked(completer.completionAt(model.index)); popup.completionClicked(completer.completionAt(model.index));
...@@ -225,6 +227,7 @@ Popup { ...@@ -225,6 +227,7 @@ Popup {
height: popup.avatarHeight height: popup.avatarHeight
width: popup.avatarWidth width: popup.avatarWidth
displayName: model.roomName displayName: model.roomName
roomid: model.roomid
url: model.avatarUrl.replace("mxc://", "image://MxcImage/") url: model.avatarUrl.replace("mxc://", "image://MxcImage/")
onClicked: popup.completionClicked(completer.completionAt(model.index)) onClicked: popup.completionClicked(completer.completionAt(model.index))
} }
......
...@@ -65,6 +65,7 @@ ApplicationWindow { ...@@ -65,6 +65,7 @@ ApplicationWindow {
width: avatarSize width: avatarSize
height: avatarSize height: avatarSize
url: model.avatarUrl.replace("mxc://", "image://MxcImage/") url: model.avatarUrl.replace("mxc://", "image://MxcImage/")
roomid: model.roomid
displayName: model.name displayName: model.name
} }
......
...@@ -143,6 +143,8 @@ Page { ...@@ -143,6 +143,8 @@ Page {
required property int notificationCount required property int notificationCount
required property bool hasLoudNotification required property bool hasLoudNotification
required property bool hasUnreadMessages required property bool hasUnreadMessages
required property bool isDirect
required property string directChatOtherUserId
color: background color: background
height: avatarSize + 2 * Nheko.paddingMedium height: avatarSize + 2 * Nheko.paddingMedium
...@@ -237,6 +239,8 @@ Page { ...@@ -237,6 +239,8 @@ Page {
width: avatarSize width: avatarSize
url: avatarUrl.replace("mxc://", "image://MxcImage/") url: avatarUrl.replace("mxc://", "image://MxcImage/")
displayName: roomName displayName: roomName
userid: isDirect ? directChatOtherUserId : ""
roomid: roomId
Rectangle { Rectangle {
id: collapsedNotificationBubble id: collapsedNotificationBubble
......
...@@ -39,6 +39,7 @@ ApplicationWindow { ...@@ -39,6 +39,7 @@ ApplicationWindow {
width: 130 width: 130
height: width height: width
roomid: members.roomId
displayName: members.roomName displayName: members.roomName
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
url: members.avatarUrl.replace("mxc://", "image://MxcImage/") url: members.avatarUrl.replace("mxc://", "image://MxcImage/")
......
...@@ -38,6 +38,7 @@ ApplicationWindow { ...@@ -38,6 +38,7 @@ ApplicationWindow {
Avatar { Avatar {
url: roomSettings.roomAvatarUrl.replace("mxc://", "image://MxcImage/") url: roomSettings.roomAvatarUrl.replace("mxc://", "image://MxcImage/")
roomid: roomSettings.roomid
displayName: roomSettings.roomName displayName: roomSettings.roomName
height: 130 height: 130
width: 130 width: 130
......
...@@ -137,6 +137,7 @@ Item { ...@@ -137,6 +137,7 @@ Item {
ColumnLayout { ColumnLayout {
id: preview id: preview
property string roomId: room ? room.roomId : (roomPreview ? roomPreview.roomId : "")
property string roomName: room ? room.roomName : (roomPreview ? roomPreview.roomName : "") property string roomName: room ? room.roomName : (roomPreview ? roomPreview.roomName : "")
property string roomTopic: room ? room.roomTopic : (roomPreview ? roomPreview.roomTopic : "") property string roomTopic: room ? room.roomTopic : (roomPreview ? roomPreview.roomTopic : "")
property string avatarUrl: room ? room.roomAvatarUrl : (roomPreview ? roomPreview.roomAvatarUrl : "") property string avatarUrl: room ? room.roomAvatarUrl : (roomPreview ? roomPreview.roomAvatarUrl : "")
...@@ -153,6 +154,7 @@ Item { ...@@ -153,6 +154,7 @@ Item {
Avatar { Avatar {
url: parent.avatarUrl.replace("mxc://", "image://MxcImage/") url: parent.avatarUrl.replace("mxc://", "image://MxcImage/")
roomid: parent.roomId
displayName: parent.roomName displayName: parent.roomName
height: 130 height: 130
width: 130 width: 130
......
...@@ -13,10 +13,13 @@ Rectangle { ...@@ -13,10 +13,13 @@ Rectangle {
property bool showBackButton: false property bool showBackButton: false
property string roomName: room ? room.roomName : qsTr("No room selected") property string roomName: room ? room.roomName : qsTr("No room selected")
property string roomId: room ? room.roomId : ""
property string avatarUrl: room ? room.roomAvatarUrl : "" property string avatarUrl: room ? room.roomAvatarUrl : ""
property string roomTopic: room ? room.roomTopic : "" property string roomTopic: room ? room.roomTopic : ""
property bool isEncrypted: room ? room.isEncrypted : false property bool isEncrypted: room ? room.isEncrypted : false
property int trustlevel: room ? room.trustlevel : Crypto.Unverified property int trustlevel: room ? room.trustlevel : Crypto.Unverified
property bool isDirect: room ? room.isDirect : false
property string directChatOtherUserId: room ? room.directChatOtherUserId : ""
Layout.fillWidth: true Layout.fillWidth: true
implicitHeight: topLayout.height + Nheko.paddingMedium * 2 implicitHeight: topLayout.height + Nheko.paddingMedium * 2
...@@ -65,10 +68,12 @@ Rectangle { ...@@ -65,10 +68,12 @@ Rectangle {
width: Nheko.avatarSize width: Nheko.avatarSize
height: Nheko.avatarSize height: Nheko.avatarSize
url: avatarUrl.replace("mxc://", "image://MxcImage/") url: avatarUrl.replace("mxc://", "image://MxcImage/")
roomid: roomId
userid: isDirect ? directChatOtherUserId : ""
displayName: roomName displayName: roomName
onClicked: { onClicked: {
if (room) if (room)
TimelineManager.openRoomSettings(room.roomId); TimelineManager.openRoomSettings(roomId);
} }
} }
...@@ -135,7 +140,7 @@ Rectangle { ...@@ -135,7 +140,7 @@ Rectangle {
Platform.MenuItem { Platform.MenuItem {
visible: room ? room.permissions.canInvite() : false visible: room ? room.permissions.canInvite() : false
text: qsTr("Invite users") text: qsTr("Invite users")
onTriggered: TimelineManager.openInviteUsers(room.roomId) onTriggered: TimelineManager.openInviteUsers(roomId)
} }
Platform.MenuItem { Platform.MenuItem {
...@@ -145,12 +150,12 @@ Rectangle { ...@@ -145,12 +150,12 @@ Rectangle {
Platform.MenuItem { Platform.MenuItem {
text: qsTr("Leave room") text: qsTr("Leave room")
onTriggered: TimelineManager.openLeaveRoomDialog(room.roomId) onTriggered: TimelineManager.openLeaveRoomDialog(roomId)
} }
Platform.MenuItem { Platform.MenuItem {
text: qsTr("Settings") text: qsTr("Settings")
onTriggered: TimelineManager.openRoomSettings(room.roomId) onTriggered: TimelineManager.openRoomSettings(roomId)
} }
} }
......
...@@ -23,6 +23,8 @@ Rectangle { ...@@ -23,6 +23,8 @@ Rectangle {
required property int index required property int index
required property int selectedIndex required property int selectedIndex
property bool crop: true property bool crop: true
property alias roomid: avatar.roomid
property alias userid: avatar.userid
color: background color: background
height: avatarSize + 2 * Nheko.paddingMedium height: avatarSize + 2 * Nheko.paddingMedium
......
...@@ -61,6 +61,7 @@ ApplicationWindow { ...@@ -61,6 +61,7 @@ ApplicationWindow {
header: AvatarListTile { header: AvatarListTile {
title: imagePack.packname title: imagePack.packname
avatarUrl: imagePack.avatarUrl avatarUrl: imagePack.avatarUrl
roomid: imagePack.statekey
subtitle: imagePack.statekey subtitle: imagePack.statekey
index: -1 index: -1
selectedIndex: currentImageIndex selectedIndex: currentImageIndex
...@@ -142,6 +143,7 @@ ApplicationWindow { ...@@ -142,6 +143,7 @@ ApplicationWindow {
Layout.columnSpan: 2 Layout.columnSpan: 2
url: imagePack.avatarUrl.replace("mxc://", "image://MxcImage/") url: imagePack.avatarUrl.replace("mxc://", "image://MxcImage/")
displayName: imagePack.packname displayName: imagePack.packname
roomid: imagePack.statekey
height: 130 height: 130
width: 130 width: 130
crop: false crop: false
...@@ -219,6 +221,7 @@ ApplicationWindow { ...@@ -219,6 +221,7 @@ ApplicationWindow {
Layout.columnSpan: 2 Layout.columnSpan: 2
url: imagePack.data(imagePack.index(currentImageIndex, 0), SingleImagePackModel.Url).replace("mxc://", "image://MxcImage/") url: imagePack.data(imagePack.index(currentImageIndex, 0), SingleImagePackModel.Url).replace("mxc://", "image://MxcImage/")
displayName: imagePack.data(imagePack.index(currentImageIndex, 0), SingleImagePackModel.ShortCode) displayName: imagePack.data(imagePack.index(currentImageIndex, 0), SingleImagePackModel.ShortCode)
roomid: displayName
height: 130 height: 130
width: 130 width: 130
crop: false crop: false
......
...@@ -112,6 +112,7 @@ ApplicationWindow { ...@@ -112,6 +112,7 @@ ApplicationWindow {
return qsTr("Globally enabled pack"); return qsTr("Globally enabled pack");
} }
selectedIndex: currentPackIndex selectedIndex: currentPackIndex
roomid: currentPack.statekey
TapHandler { TapHandler {
onSingleTapped: currentPackIndex = index onSingleTapped: currentPackIndex = index
...@@ -135,6 +136,7 @@ ApplicationWindow { ...@@ -135,6 +136,7 @@ ApplicationWindow {
property string packName: currentPack ? currentPack.packname : "" property string packName: currentPack ? currentPack.packname : ""
property string attribution: currentPack ? currentPack.attribution : "" property string attribution: currentPack ? currentPack.attribution : ""
property string avatarUrl: currentPack ? currentPack.avatarUrl : "" property string avatarUrl: currentPack ? currentPack.avatarUrl : ""
property string statekey: currentPack ? currentPack.statekey : ""
anchors.fill: parent anchors.fill: parent
anchors.margins: Nheko.paddingLarge anchors.margins: Nheko.paddingLarge
...@@ -143,6 +145,7 @@ ApplicationWindow { ...@@ -143,6 +145,7 @@ ApplicationWindow {
Avatar { Avatar {
url: packinfo.avatarUrl.replace("mxc://", "image://MxcImage/") url: packinfo.avatarUrl.replace("mxc://", "image://MxcImage/")
displayName: packinfo.packName displayName: packinfo.packName
roomid: packinfo.statekey
height: 100 height: 100
width: 100 width: 100
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
......
...@@ -34,14 +34,15 @@ Rectangle { ...@@ -34,14 +34,15 @@ Rectangle {
width: Nheko.avatarSize width: Nheko.avatarSize
height: Nheko.avatarSize height: Nheko.avatarSize
url: CallManager.callPartyAvatarUrl.replace("mxc://", "image://MxcImage/") url: CallManager.callPartyAvatarUrl.replace("mxc://", "image://MxcImage/")
displayName: CallManager.callParty userid: CallManager.callParty
displayName: CallManager.callPartyDisplayName
onClicked: TimelineManager.openImageOverlay(room.avatarUrl(userid), room.data.eventId) onClicked: TimelineManager.openImageOverlay(room.avatarUrl(userid), room.data.eventId)
} }
Label { Label {
Layout.leftMargin: 8 Layout.leftMargin: 8
font.pointSize: fontMetrics.font.pointSize * 1.1 font.pointSize: fontMetrics.font.pointSize * 1.1
text: CallManager.callParty text: CallManager.callPartyDisplayName
color: "#000000" color: "#000000"
} }
......
...@@ -40,7 +40,7 @@ Popup { ...@@ -40,7 +40,7 @@ Popup {
Label { Label {
Layout.alignment: Qt.AlignCenter Layout.alignment: Qt.AlignCenter
Layout.topMargin: msgView.height / 25 Layout.topMargin: msgView.height / 25
text: CallManager.callParty text: CallManager.callPartyDisplayName
font.pointSize: fontMetrics.font.pointSize * 2 font.pointSize: fontMetrics.font.pointSize * 2
color: Nheko.colors.windowText color: Nheko.colors.windowText
} }
...@@ -50,7 +50,8 @@ Popup { ...@@ -50,7 +50,8 @@ Popup {
width: msgView.height / 5 width: msgView.height / 5
height: msgView.height / 5 height: msgView.height / 5
url: CallManager.callPartyAvatarUrl.replace("mxc://", "image://MxcImage/") url: CallManager.callPartyAvatarUrl.replace("mxc://", "image://MxcImage/")
displayName: CallManager.callParty userid: CallManager.callParty
displayName: CallManager.callPartyDisplayName
} }
ColumnLayout { ColumnLayout {
......
...@@ -41,14 +41,15 @@ Rectangle { ...@@ -41,14 +41,15 @@ Rectangle {
width: Nheko.avatarSize width: Nheko.avatarSize
height: Nheko.avatarSize height: Nheko.avatarSize
url: CallManager.callPartyAvatarUrl.replace("mxc://", "image://MxcImage/") url: CallManager.callPartyAvatarUrl.replace("mxc://", "image://MxcImage/")
displayName: CallManager.callParty userid: CallManager.callParty
displayName: CallManager.callPartyDisplayName
onClicked: TimelineManager.openImageOverlay(room.avatarUrl(userid), room.data.eventId) onClicked: TimelineManager.openImageOverlay(room.avatarUrl(userid), room.data.eventId)
} }
Label { Label {
Layout.leftMargin: 8 Layout.leftMargin: 8
font.pointSize: fontMetrics.font.pointSize * 1.1 font.pointSize: fontMetrics.font.pointSize * 1.1
text: CallManager.callParty text: CallManager.callPartyDisplayName
color: "#000000" color: "#000000"
} }
......
...@@ -79,6 +79,7 @@ Popup { ...@@ -79,6 +79,7 @@ Popup {
height: Nheko.avatarSize height: Nheko.avatarSize
url: room.roomAvatarUrl.replace("mxc://", "image://MxcImage/") url: room.roomAvatarUrl.replace("mxc://", "image://MxcImage/")
displayName: room.roomName displayName: room.roomName
roomid: room.roomid
onClicked: TimelineManager.openImageOverlay(room.avatarUrl(userid), room.data.eventId) onClicked: TimelineManager.openImageOverlay(room.avatarUrl(userid), room.data.eventId)
} }
......
...@@ -2776,6 +2776,46 @@ Cache::getMembers(const std::string &room_id, std::size_t startIndex, std::size_ ...@@ -2776,6 +2776,46 @@ Cache::getMembers(const std::string &room_id, std::size_t startIndex, std::size_
return members; return members;
} }
std::vector<RoomMember>
Cache::getMembersFromInvite(const std::string &room_id, std::size_t startIndex, std::size_t len)
{
auto txn = ro_txn(env_);
auto db = getInviteMembersDb(txn, room_id);
auto cursor = lmdb::cursor::open(txn, db);
std::size_t currentIndex = 0;
const auto endIndex = std::min(startIndex + len, db.size(txn));
std::vector<RoomMember> members;
std::string_view user_id, user_data;
while (cursor.get(user_id, user_data, MDB_NEXT)) {
if (currentIndex < startIndex) {
currentIndex += 1;
continue;
}
if (currentIndex >= endIndex)
break;
try {
MemberInfo tmp = json::parse(user_data);
members.emplace_back(
RoomMember{QString::fromStdString(std::string(user_id)),
QString::fromStdString(tmp.name)});
} catch (const json::exception &e) {
nhlog::db()->warn("{}", e.what());
}
currentIndex += 1;
}
cursor.close();
return members;
}
bool bool
Cache::isRoomMember(const std::string &user_id, const std::string &room_id) Cache::isRoomMember(const std::string &user_id, const std::string &room_id)
{ {
...@@ -4808,6 +4848,12 @@ getMembers(const std::string &room_id, std::size_t startIndex, std::size_t len) ...@@ -4808,6 +4848,12 @@ getMembers(const std::string &room_id, std::size_t startIndex, std::size_t len)
return instance_->getMembers(room_id, startIndex, len); return instance_->getMembers(room_id, startIndex, len);
} }
std::vector<RoomMember>
getMembersFromInvite(const std::string &room_id, std::size_t startIndex, std::size_t len)
{
return instance_->getMembersFromInvite(room_id, startIndex, len);
}
void void
saveState(const mtx::responses::Sync &res) saveState(const mtx::responses::Sync &res)
{ {
......
...@@ -83,6 +83,9 @@ getRoomAvatarUrl(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &membersdb); ...@@ -83,6 +83,9 @@ getRoomAvatarUrl(lmdb::txn &txn, lmdb::dbi &statesdb, lmdb::dbi &membersdb);
//! Retrieve member info from a room. //! Retrieve member info from a room.
std::vector<RoomMember> std::vector<RoomMember>
getMembers(const std::string &room_id, std::size_t startIndex = 0, std::size_t len = 30); getMembers(const std::string &room_id, std::size_t startIndex = 0, std::size_t len = 30);
//! Retrive member info from an invite.
std::vector<RoomMember>
getMembersFromInvite(const std::string &room_id, std::size_t start_index = 0, std::size_t len = 30);
bool bool
isInitialized(); isInitialized();
......
...@@ -93,7 +93,7 @@ to_json(nlohmann::json &j, const RoomInfo &info); ...@@ -93,7 +93,7 @@ to_json(nlohmann::json &j, const RoomInfo &info);
void void
from_json(const nlohmann::json &j, RoomInfo &info); from_json(const nlohmann::json &j, RoomInfo &info);
//! Basic information per member; //! Basic information per member.
struct MemberInfo struct MemberInfo
{ {
std::string name; std::string name;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment