From 2bb346a09e3d8b9d1cce613c2a6f48001a29f4f6 Mon Sep 17 00:00:00 2001 From: Michal Iskierko Date: Tue, 6 Sep 2022 17:06:33 +0200 Subject: [PATCH] fix(@desktop): Use colorId to find correct color of users&members colorId is set in the model instead of using qml function. Fix #6366 --- .../chat_section/chat_content/users/module.nim | 2 ++ src/app/modules/main/chat_section/module.nim | 1 + src/app/modules/main/communities/module.nim | 1 + src/app/modules/main/module.nim | 4 ++++ .../main/profile_section/contacts/controller.nim | 3 +++ .../main/profile_section/contacts/module.nim | 7 ++++--- src/app/modules/shared_models/member_item.nim | 2 +- src/app/modules/shared_models/user_item.nim | 2 +- .../service/contacts/dto/contact_details.nim | 1 + src/app_service/service/contacts/service.nim | 3 +++ ui/app/AppLayouts/Chat/panels/ContactListPanel.qml | 2 +- ui/app/AppLayouts/Chat/panels/UserListPanel.qml | 2 +- .../communities/CommunityMembersTabPanel.qml | 2 +- ui/app/AppLayouts/Chat/popups/GroupInfoPopup.qml | 2 +- ui/imports/shared/views/ExistingContacts.qml | 2 +- ui/imports/shared/views/PickedContacts.qml | 2 +- ui/imports/utils/Utils.qml | 14 ++++++++------ 17 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/app/modules/main/chat_section/chat_content/users/module.nim b/src/app/modules/main/chat_section/chat_content/users/module.nim index eadb680c12..35684ceaa5 100644 --- a/src/app/modules/main/chat_section/chat_content/users/module.nim +++ b/src/app/modules/main/chat_section/chat_content/users/module.nim @@ -80,6 +80,7 @@ method onNewMessagesLoaded*(self: Module, messages: seq[MessageDto]) = localNickname = contactDetails.details.localNickname, alias = contactDetails.details.alias, icon = contactDetails.icon, + colorId = contactDetails.colorId, onlineStatus = status, isContact = contactDetails.details.isContact, isUntrustworthy = contactDetails.details.trustStatus == TrustStatus.Untrustworthy, @@ -147,6 +148,7 @@ method addChatMember*(self: Module, member: ChatMember) = localNickname = contactDetails.details.localNickname, alias = contactDetails.details.alias, icon = contactDetails.icon, + colorId = contactDetails.colorId, onlineStatus = status, isContact = contactDetails.details.isContact, isAdmin = member.admin, diff --git a/src/app/modules/main/chat_section/module.nim b/src/app/modules/main/chat_section/module.nim index be7a9b7896..24f1f74e62 100644 --- a/src/app/modules/main/chat_section/module.nim +++ b/src/app/modules/main/chat_section/module.nim @@ -215,6 +215,7 @@ proc createItemFromPublicKey(self: Module, publicKey: string): UserItem = pubKey = contactDetails.details.id, displayName = contactDetails.displayName, icon = contactDetails.icon, + colorId = contactDetails.colorId, onlineStatus = toOnlineStatus(self.controller.getStatusForContactWithId(publicKey).statusType), isContact = contactDetails.details.isContact(), isVerified = contactDetails.details.isContactVerified(), diff --git a/src/app/modules/main/communities/module.nim b/src/app/modules/main/communities/module.nim index b1a72d4f01..cd34a1192a 100644 --- a/src/app/modules/main/communities/module.nim +++ b/src/app/modules/main/communities/module.nim @@ -87,6 +87,7 @@ proc createMemberItem(self: Module, memberId, requestId: string): MemberItem = localNickname = contactDetails.details.localNickname, alias = contactDetails.details.alias, icon = contactDetails.icon, + colorId = contactDetails.colorId, onlineStatus = toOnlineStatus(self.controller.getStatusForContactWithId(memberId).statusType), isContact = contactDetails.details.isContact, requestToJoinId = requestId) diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index 894740ae58..fd64fa5f51 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -237,6 +237,7 @@ proc createChannelGroupItem[T](self: Module[T], c: ChannelGroupDto): SectionItem localNickname = contactDetails.details.localNickname, alias = contactDetails.details.alias, icon = contactDetails.icon, + colorId = contactDetails.colorId, onlineStatus = toOnlineStatus(self.controller.getStatusForContactWithId(member.id).statusType), isContact = contactDetails.details.isContact, isAdmin = member.admin @@ -260,6 +261,7 @@ proc createChannelGroupItem[T](self: Module[T], c: ChannelGroupDto): SectionItem localNickname = contactDetails.details.localNickname, alias = contactDetails.details.alias, icon = contactDetails.icon, + colorId = contactDetails.colorId, onlineStatus = toOnlineStatus(self.controller.getStatusForContactWithId(bannedMemberId).statusType), isContact = contactDetails.details.isContact ) @@ -273,6 +275,7 @@ proc createChannelGroupItem[T](self: Module[T], c: ChannelGroupDto): SectionItem localNickname = contactDetails.details.localNickname, alias = contactDetails.details.alias, icon = contactDetails.icon, + colorId = contactDetails.colorId, onlineStatus = toOnlineStatus(self.controller.getStatusForContactWithId(requestDto.publicKey).statusType), isContact = contactDetails.details.isContact, requestToJoinId = requestDto.id @@ -287,6 +290,7 @@ proc createChannelGroupItem[T](self: Module[T], c: ChannelGroupDto): SectionItem localNickname = contactDetails.details.localNickname, alias = contactDetails.details.alias, icon = contactDetails.icon, + colorId = contactDetails.colorId, onlineStatus = toOnlineStatus(self.controller.getStatusForContactWithId(requestDto.publicKey).statusType), isContact = contactDetails.details.isContact, requestToJoinId = requestDto.id diff --git a/src/app/modules/main/profile_section/contacts/controller.nim b/src/app/modules/main/profile_section/contacts/controller.nim index f92d6d7eba..669cdda3d3 100644 --- a/src/app/modules/main/profile_section/contacts/controller.nim +++ b/src/app/modules/main/profile_section/contacts/controller.nim @@ -91,6 +91,9 @@ proc getContactNameAndImage*(self: Controller, contactId: string): tuple[name: string, image: string, largeImage: string] = return self.contactsService.getContactNameAndImage(contactId) +proc getContactDetails*(self: Controller, contactId: string): ContactDetails = + return self.contactsService.getContactDetails(contactId) + proc unblockContact*(self: Controller, publicKey: string) = self.contactsService.unblockContact(publicKey) diff --git a/src/app/modules/main/profile_section/contacts/module.nim b/src/app/modules/main/profile_section/contacts/module.nim index 063664d46b..80f4cab37f 100644 --- a/src/app/modules/main/profile_section/contacts/module.nim +++ b/src/app/modules/main/profile_section/contacts/module.nim @@ -41,12 +41,13 @@ method delete*(self: Module) = proc createItemFromPublicKey(self: Module, publicKey: string): UserItem = let contact = self.controller.getContact(publicKey) - let (name, image, _) = self.controller.getContactNameAndImage(contact.id) + let contactDetails = self.controller.getContactDetails(contact.id) return initUserItem( pubKey = contact.id, - displayName = name, - icon = image, + displayName = contactDetails.displayName, + icon = contactDetails.icon, + colorId = contactDetails.colorId, onlineStatus = toOnlineStatus(self.controller.getStatusForContactWithId(publicKey).statusType), isContact = contact.isContact(), isBlocked = contact.isBlocked(), diff --git a/src/app/modules/shared_models/member_item.nim b/src/app/modules/shared_models/member_item.nim index ed3d6e219c..d4f35ed82a 100644 --- a/src/app/modules/shared_models/member_item.nim +++ b/src/app/modules/shared_models/member_item.nim @@ -17,7 +17,7 @@ proc initMemberItem*( localNickname: string, alias: string, icon: string, - colorId: int = 0, + colorId: int, colorHash: string = "", onlineStatus: OnlineStatus = OnlineStatus.Inactive, isContact: bool = false, diff --git a/src/app/modules/shared_models/user_item.nim b/src/app/modules/shared_models/user_item.nim index 37cfdcc3e4..01d1f1df9d 100644 --- a/src/app/modules/shared_models/user_item.nim +++ b/src/app/modules/shared_models/user_item.nim @@ -83,7 +83,7 @@ proc initUserItem*( localNickname: string = "", alias: string = "", icon: string, - colorId: int = 0, + colorId: int, colorHash: string = "", onlineStatus: OnlineStatus, isContact: bool, diff --git a/src/app_service/service/contacts/dto/contact_details.nim b/src/app_service/service/contacts/dto/contact_details.nim index d6271adfc5..2b8594d2e6 100644 --- a/src/app_service/service/contacts/dto/contact_details.nim +++ b/src/app_service/service/contacts/dto/contact_details.nim @@ -9,4 +9,5 @@ type displayName*: string icon*: string isCurrentUser*: bool + colorId*: int details*: ContactsDto diff --git a/src/app_service/service/contacts/service.nim b/src/app_service/service/contacts/service.nim index d573a92d49..2519654ef0 100644 --- a/src/app_service/service/contacts/service.nim +++ b/src/app_service/service/contacts/service.nim @@ -8,6 +8,8 @@ import ../../common/types as common_types import ../settings/service as settings_service import ../network/service as network_service +import ../visual_identity/service as procs_from_visual_identity_service + import ./dto/contacts as contacts_dto import ./dto/status_update as status_update_dto import ./dto/contact_details @@ -514,6 +516,7 @@ QtObject: let (name, icon, _) = self.getContactNameAndImage(pubKey) result.displayName = name result.icon = icon + result.colorId = procs_from_visual_identity_service.colorIdOf(pubKey) result.isCurrentUser = pubKey == singletonInstance.userProfile.getPubKey() result.details = self.getContactById(pubKey) diff --git a/ui/app/AppLayouts/Chat/panels/ContactListPanel.qml b/ui/app/AppLayouts/Chat/panels/ContactListPanel.qml index 002a55ac2c..1941370939 100644 --- a/ui/app/AppLayouts/Chat/panels/ContactListPanel.qml +++ b/ui/app/AppLayouts/Chat/panels/ContactListPanel.qml @@ -39,7 +39,7 @@ StatusListView { asset.width: asset.isImage ? 40 : 20 asset.name: model.icon asset.isImage: model.icon !== "" - asset.color: Utils.colorForPubkey(model.pubKey) + asset.color: Utils.colorForColorId(model.colorId) asset.charactersLen: 2 ringSettings.ringSpecModel: Utils.getColorHashAsJson(model.pubKey) diff --git a/ui/app/AppLayouts/Chat/panels/UserListPanel.qml b/ui/app/AppLayouts/Chat/panels/UserListPanel.qml index d6d3be8a86..7e294e4297 100644 --- a/ui/app/AppLayouts/Chat/panels/UserListPanel.qml +++ b/ui/app/AppLayouts/Chat/panels/UserListPanel.qml @@ -95,7 +95,7 @@ Item { } asset.isImage: (asset.name !== "") asset.isLetterIdenticon: (asset.name === "") - asset.color: Utils.colorForPubkey(model.pubKey) // FIXME: use model.colorId + asset.color: Utils.colorForColorId(model.colorId) status: model.onlineStatus ringSettings.ringSpecModel: Utils.getColorHashAsJson(model.pubKey) // FIXME: use model.colorHash onClicked: { diff --git a/ui/app/AppLayouts/Chat/panels/communities/CommunityMembersTabPanel.qml b/ui/app/AppLayouts/Chat/panels/communities/CommunityMembersTabPanel.qml index 6193365c4b..9efdc00c21 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 - asset.color: Utils.colorForPubkey(model.pubKey) // FIXME: use model.colorId + asset.color: Utils.colorForColorId(model.colorId) asset.name: model.icon asset.isImage: true asset.imgIsIdenticon: false diff --git a/ui/app/AppLayouts/Chat/popups/GroupInfoPopup.qml b/ui/app/AppLayouts/Chat/popups/GroupInfoPopup.qml index a3b5052ea3..ebb2f564b8 100644 --- a/ui/app/AppLayouts/Chat/popups/GroupInfoPopup.qml +++ b/ui/app/AppLayouts/Chat/popups/GroupInfoPopup.qml @@ -216,7 +216,7 @@ StatusModal { asset.name: model.icon asset.isImage: !!model.icon ringSettings.ringSpecModel: Utils.getColorHashAsJson(model.pubKey) - asset.color: Utils.colorForPubkey(model.pubKey) + asset.color: Utils.colorForColorId(model.colorId) asset.charactersLen: 2 asset.isLetterIdenticon: model.icon === "" asset.height: asset.isLetterIdenticon ? 40 : 20 diff --git a/ui/imports/shared/views/ExistingContacts.qml b/ui/imports/shared/views/ExistingContacts.qml index e5b7b7f27e..d696aa7999 100644 --- a/ui/imports/shared/views/ExistingContacts.qml +++ b/ui/imports/shared/views/ExistingContacts.qml @@ -58,7 +58,7 @@ Item { asset.imgIsIdenticon: false asset.width: 40 asset.height: 40 - asset.color: Utils.colorForPubkey(model.pubKey) + asset.color: Utils.colorForColorId(model.colorId) ringSettings.ringSpecModel: Utils.getColorHashAsJson(model.pubKey) statusListItemIcon.badge.border.color: Theme.palette.baseColor4 statusListItemIcon.badge.implicitHeight: 14 // 10 px + 2 px * 2 borders diff --git a/ui/imports/shared/views/PickedContacts.qml b/ui/imports/shared/views/PickedContacts.qml index 3fbbfa587f..3d5a74bef5 100644 --- a/ui/imports/shared/views/PickedContacts.qml +++ b/ui/imports/shared/views/PickedContacts.qml @@ -58,7 +58,7 @@ Item { asset.width: 40 asset.height: 40 color: "transparent" - asset.color: Utils.colorForPubkey(model.pubKey) + asset.color: Utils.colorForColorId(model.colorId) ringSettings.ringSpecModel: Utils.getColorHashAsJson(model.pubKey) statusListItemIcon.badge.border.color: Theme.palette.baseColor4 statusListItemIcon.badge.implicitHeight: 14 // 10 px + 2 px * 2 borders diff --git a/ui/imports/utils/Utils.qml b/ui/imports/utils/Utils.qml index 2c66c26622..f1edd283ab 100644 --- a/ui/imports/utils/Utils.qml +++ b/ui/imports/utils/Utils.qml @@ -576,15 +576,17 @@ QtObject { return globalUtils.getColorId(publicKey) } - function colorForPubkey(publicKey) { - const pubKeyColorId = colorIdForPubkey(publicKey) - - if (pubKeyColorId < 0 || pubKeyColorId >= Theme.palette.userCustomizationColors.length) { - console.warn("Utils.colorForPubkey : colorId for publicKey is out of bounds") + function colorForColorId(colorId) { + if (colorId < 0 || colorId >= Theme.palette.userCustomizationColors.length) { + console.warn("Utils.colorForColorId : colorId is out of bounds") return StatusColors.colors['blue'] } + return Theme.palette.userCustomizationColors[colorId] + } - return Theme.palette.userCustomizationColors[pubKeyColorId] + function colorForPubkey(publicKey) { + const pubKeyColorId = colorIdForPubkey(publicKey) + return colorForColorId(pubKeyColorId) } function getCompressedPk(publicKey) {