From 84034d5dbf567b4b3db99e3635577387d1c8bb9c Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Tue, 2 Mar 2021 15:43:32 -0500 Subject: [PATCH] fix: fix channel color in communities --- src/app/chat/view.nim | 36 ++++++++++++------- .../MessageComponents/ChannelIdentifier.qml | 9 ++++- ui/app/AppLayouts/Chat/ChatColumn/TopBar.qml | 1 + .../Chat/ContactsColumn/Channel.qml | 1 + .../Chat/components/GroupInfoPopup.qml | 1 + ui/shared/status/StatusChatInfo.qml | 1 + ui/shared/status/StatusIdenticon.qml | 2 ++ ui/shared/status/StatusLetterIdenticon.qml | 3 +- 8 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/app/chat/view.nim b/src/app/chat/view.nim index eaefa5071b..4544fc692c 100644 --- a/src/app/chat/view.nim +++ b/src/app/chat/view.nim @@ -91,6 +91,25 @@ QtObject: result.setup() + + proc getChannel*(self: ChatsView, index: int): Chat = + if (self.communities.activeCommunity.active): + return self.communities.activeCommunity.chats.getChannel(index) + else: + return self.chats.getChannel(index) + + proc getChannelById*(self: ChatsView, channel: string): Chat = + if (self.communities.activeCommunity.active): + return self.communities.activeCommunity.chats.getChannel(self.communities.activeCommunity.chats.chats.findIndexById(channel)) + else: + return self.chats.getChannel(self.chats.chats.findIndexById(channel)) + + proc updateChannelInRightList*(self: ChatsView, channel: Chat) = + if (self.communities.activeCommunity.active): + self.communities.activeCommunity.chats.updateChat(channel) + else: + self.chats.updateChat(channel) + proc oldestMessageTimestampChanged*(self: ChatsView) {.signal.} proc getOldestMessageTimestamp*(self: ChatsView): QVariant {.slot.} = @@ -125,7 +144,10 @@ QtObject: read = getCommunities proc getChannelColor*(self: ChatsView, channel: string): string {.slot.} = - self.chats.getChannelColor(channel) + if (channel == ""): return + let selectedChannel = self.getChannelById(channel) + if (selectedChannel.id == "") : return + return selectedChannel.color proc replaceMentionsWithPubKeys(self: ChatsView, mentions: seq[string], contacts: seq[Profile], message: string, predicate: proc (contact: Profile): string): string = var updatedMessage = message @@ -168,18 +190,6 @@ QtObject: channelId = "@" & self.pubKey self.status.chat.sendMessage(channelId, m, replyTo, contentType) - - proc getChannel*(self: ChatsView, index: int): Chat = - if (self.communities.activeCommunity.active): - return self.communities.activeCommunity.chats.getChannel(index) - else: - return self.chats.getChannel(index) - - proc getChannelById*(self: ChatsView, channel: string): Chat = - if (self.communities.activeCommunity.active): - return self.communities.activeCommunity.chats.getChannel(self.communities.activeCommunity.chats.chats.findIndexById(channel)) - else: - return self.chats.getChannel(self.chats.chats.findIndexById(channel)) proc verifyMessageSent*(self: ChatsView, data: string) {.slot.} = let messageData = data.parseJson diff --git a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChannelIdentifier.qml b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChannelIdentifier.qml index 1fea67c788..ed4aaae907 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChannelIdentifier.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/MessageComponents/ChannelIdentifier.qml @@ -27,7 +27,14 @@ Column { if (chatsModel.activeChannel.chatType === Constants.chatTypeOneToOne) { return Style.current.transparent } - return chatsModel.activeChannel.color + if (chatsModel.activeChannel.color) { + return chatsModel.activeChannel.color + } + const color = chatsModel.getChannelColor(chatId) + if (!color) { + return Style.current.orange + } + return color } RoundedImage { diff --git a/ui/app/AppLayouts/Chat/ChatColumn/TopBar.qml b/ui/app/AppLayouts/Chat/ChatColumn/TopBar.qml index 80f703c556..3bc82aaae0 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/TopBar.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/TopBar.qml @@ -60,6 +60,7 @@ Rectangle { id: chatInfo StatusChatInfo { identiconSize: 36 + chatId: chatsModel.activeChannel.id chatName: chatsModel.activeChannel.name chatType: chatsModel.activeChannel.chatType identicon: chatsModel.activeChannel.identicon diff --git a/ui/app/AppLayouts/Chat/ContactsColumn/Channel.qml b/ui/app/AppLayouts/Chat/ContactsColumn/Channel.qml index e3b6763b9b..24a0fed682 100644 --- a/ui/app/AppLayouts/Chat/ContactsColumn/Channel.qml +++ b/ui/app/AppLayouts/Chat/ContactsColumn/Channel.qml @@ -56,6 +56,7 @@ Rectangle { id: contactImage height: !isCompact ? 40 : 28 width: !isCompact ? 40 : 28 + chatId: wrapper.chatId chatName: wrapper.name chatType: wrapper.chatType identicon: wrapper.profileImage || wrapper.identicon diff --git a/ui/app/AppLayouts/Chat/components/GroupInfoPopup.qml b/ui/app/AppLayouts/Chat/components/GroupInfoPopup.qml index 1127ade93c..acd5db171b 100644 --- a/ui/app/AppLayouts/Chat/components/GroupInfoPopup.qml +++ b/ui/app/AppLayouts/Chat/components/GroupInfoPopup.qml @@ -61,6 +61,7 @@ ModalPopup { height: 36 anchors.top: parent.top color: popup.channel.color + chatId: popup.channel.id chatName: popup.channel.name } diff --git a/ui/shared/status/StatusChatInfo.qml b/ui/shared/status/StatusChatInfo.qml index 90f13c55d5..3d9948eacf 100644 --- a/ui/shared/status/StatusChatInfo.qml +++ b/ui/shared/status/StatusChatInfo.qml @@ -34,6 +34,7 @@ Item { StatusIdenticon { id: chatIdenticon chatType: root.chatType + chatId: root.chatId chatName: root.chatName identicon: root.profileImage || root.identicon width: root.isCompact ? 20 : root.identiconSize diff --git a/ui/shared/status/StatusIdenticon.qml b/ui/shared/status/StatusIdenticon.qml index d9fa271518..4b2b310e4f 100644 --- a/ui/shared/status/StatusIdenticon.qml +++ b/ui/shared/status/StatusIdenticon.qml @@ -6,6 +6,7 @@ import "../../shared/status" Item { id: root + property string chatId property string chatName property int chatType property string identicon @@ -22,6 +23,7 @@ Item { id: letterIdenticon StatusLetterIdenticon { + chatId: root.chatId chatName: root.chatName width: parent.width height: parent.height diff --git a/ui/shared/status/StatusLetterIdenticon.qml b/ui/shared/status/StatusLetterIdenticon.qml index f40345cd65..3c80e87caa 100644 --- a/ui/shared/status/StatusLetterIdenticon.qml +++ b/ui/shared/status/StatusLetterIdenticon.qml @@ -5,6 +5,7 @@ import "../../shared" Rectangle { id: root + property string chatId property string chatName width: 40 @@ -12,7 +13,7 @@ Rectangle { radius: width / 2 color: { - const color = chatsModel.getChannelColor(root.chatName.startsWith("#") ? root.chatName.substr(1) : root.chatName) + const color = chatsModel.getChannelColor(chatId) if (!color) { return Style.current.orange }