From 38c77095b8a25bfa9eec4c416231b9c4ebb0f233 Mon Sep 17 00:00:00 2001 From: PavelS Date: Fri, 19 Aug 2022 13:01:54 +0300 Subject: [PATCH] fix(@desktop/chat): adjust add members default picture Update colorForPubkey to check if colorId is in bounds Replace userCustomizationColors array usage with Utils function call Fixes #6971 --- ui/app/AppLayouts/Chat/panels/ContactListPanel.qml | 10 +++++++++- ui/app/AppLayouts/Chat/panels/UserListPanel.qml | 2 +- .../panels/communities/CommunityMembersTabPanel.qml | 2 +- ui/app/AppLayouts/Chat/popups/GroupInfoPopup.qml | 2 +- .../Profile/popups/ExemptionNotificationsModal.qml | 2 +- ui/app/AppLayouts/Profile/views/NotificationsView.qml | 2 +- ui/imports/utils/Utils.qml | 9 ++++++++- 7 files changed, 22 insertions(+), 7 deletions(-) diff --git a/ui/app/AppLayouts/Chat/panels/ContactListPanel.qml b/ui/app/AppLayouts/Chat/panels/ContactListPanel.qml index d66a9f28f3..9c35ae8d72 100644 --- a/ui/app/AppLayouts/Chat/panels/ContactListPanel.qml +++ b/ui/app/AppLayouts/Chat/panels/ContactListPanel.qml @@ -4,6 +4,7 @@ import QtQuick.Controls 2.3 import StatusQ.Core 0.1 import StatusQ.Components 0.1 import StatusQ.Controls 0.1 +import StatusQ.Core.Theme 0.1 import utils 1.0 @@ -34,7 +35,14 @@ StatusListView { title: !model.displayName.endsWith(".eth") && !!model.localNickname ? model.localNickname : Utils.removeStatusEns(model.displayName) - image.source: Global.getProfileImage(model.pubKey) + image.source: model.icon + icon: StatusIconSettings { + color: Utils.colorForPubkey(model.pubKey) + charactersLen: 2 + isLetterIdenticon: model.icon === "" + height: isLetterIdenticon ? 40 : 20 + width: isLetterIdenticon ? 40 : 20 + } ringSettings.ringSpecModel: Utils.getColorHashAsJson(model.pubKey) height: visible ? implicitHeight : 0 diff --git a/ui/app/AppLayouts/Chat/panels/UserListPanel.qml b/ui/app/AppLayouts/Chat/panels/UserListPanel.qml index 8061cc648f..d4887c3dad 100644 --- a/ui/app/AppLayouts/Chat/panels/UserListPanel.qml +++ b/ui/app/AppLayouts/Chat/panels/UserListPanel.qml @@ -95,7 +95,7 @@ Item { image.isIdenticon: false status: model.onlineStatus - icon.color: Theme.palette.userCustomizationColors[Utils.colorIdForPubkey(model.pubKey)] // FIXME: use model.colorId + icon.color: Utils.colorForPubkey(model.pubKey) // FIXME: use model.colorId ringSettings.ringSpecModel: Utils.getColorHashAsJson(model.pubKey) // FIXME: use model.colorHash onClicked: { if (mouse.button === Qt.RightButton) { diff --git a/ui/app/AppLayouts/Chat/panels/communities/CommunityMembersTabPanel.qml b/ui/app/AppLayouts/Chat/panels/communities/CommunityMembersTabPanel.qml index ab220ecc30..badca639eb 100644 --- a/ui/app/AppLayouts/Chat/panels/communities/CommunityMembersTabPanel.qml +++ b/ui/app/AppLayouts/Chat/panels/communities/CommunityMembersTabPanel.qml @@ -140,7 +140,7 @@ Item { nickName: model.localNickname userName: model.displayName status: model.onlineStatus - icon.color: Theme.palette.userCustomizationColors[Utils.colorIdForPubkey(model.pubKey)] // FIXME: use model.colorId + icon.color: Utils.colorForPubkey(model.pubKey) // FIXME: use model.colorId image.source: model.icon image.isIdenticon: false image.width: 40 diff --git a/ui/app/AppLayouts/Chat/popups/GroupInfoPopup.qml b/ui/app/AppLayouts/Chat/popups/GroupInfoPopup.qml index 6c77b143a7..02d259405e 100644 --- a/ui/app/AppLayouts/Chat/popups/GroupInfoPopup.qml +++ b/ui/app/AppLayouts/Chat/popups/GroupInfoPopup.qml @@ -208,7 +208,7 @@ StatusModal { image.source: model.icon ringSettings.ringSpecModel: Utils.getColorHashAsJson(model.pubKey) icon: StatusIconSettings { - color: Theme.palette.userCustomizationColors[Utils.colorIdForPubkey(model.pubKey)] + color: Utils.colorForPubkey(model.pubKey) charactersLen: 2 isLetterIdenticon: model.icon === "" height: isLetterIdenticon ? 40 : 20 diff --git a/ui/app/AppLayouts/Profile/popups/ExemptionNotificationsModal.qml b/ui/app/AppLayouts/Profile/popups/ExemptionNotificationsModal.qml index 948d1fdcfc..55ec30f438 100644 --- a/ui/app/AppLayouts/Profile/popups/ExemptionNotificationsModal.qml +++ b/ui/app/AppLayouts/Profile/popups/ExemptionNotificationsModal.qml @@ -38,7 +38,7 @@ StatusModal { // root.item.color // until then the following is used background.color: root.item.type === Constants.settingsSection.exemptions.oneToOneChat? - Theme.palette.userCustomizationColors[Utils.colorIdForPubkey(root.item.itemId)] : + Utils.colorForPubkey(root.item.itemId) : root.item.color charactersLen: root.item.type === Constants.settingsSection.exemptions.oneToOneChat? 2 : 1 isLetterIdenticon: root.item.image === "" diff --git a/ui/app/AppLayouts/Profile/views/NotificationsView.qml b/ui/app/AppLayouts/Profile/views/NotificationsView.qml index dfb0e6a529..b6b65cf697 100644 --- a/ui/app/AppLayouts/Profile/views/NotificationsView.qml +++ b/ui/app/AppLayouts/Profile/views/NotificationsView.qml @@ -123,7 +123,7 @@ SettingsContentBase { ringSettings.ringSpecModel: model.type === Constants.settingsSection.exemptions.oneToOneChat ? Utils.getColorHashAsJson(model.itemId) : undefined icon: StatusIconSettings { color: model.type === Constants.settingsSection.exemptions.oneToOneChat? - Theme.palette.userCustomizationColors[Utils.colorIdForPubkey(model.itemId)] : + Utils.colorForPubkey(model.itemId) : model.color charactersLen: model.type === Constants.settingsSection.exemptions.oneToOneChat? 2 : 1 isLetterIdenticon: model.image === "" diff --git a/ui/imports/utils/Utils.qml b/ui/imports/utils/Utils.qml index d4d396c38b..239993db34 100644 --- a/ui/imports/utils/Utils.qml +++ b/ui/imports/utils/Utils.qml @@ -577,7 +577,14 @@ QtObject { } function colorForPubkey(publicKey) { - return Theme.palette.userCustomizationColors[colorIdForPubkey(publicKey)] + const pubKeyColorId = colorIdForPubkey(publicKey) + + if (pubKeyColorId < 0 || pubKeyColorId >= Theme.palette.userCustomizationColors.length) { + console.warn("Utils.colorForPubkey : colorId for publicKey is out of bounds") + return StatusColors.colors['blue'] + } + + return Theme.palette.userCustomizationColors[pubKeyColorId] } function getCompressedPk(publicKey) {