From 2da4abf8eb99603936360862ffdf62377f92ffa4 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Fri, 2 Oct 2020 15:25:33 -0400 Subject: [PATCH] fix: "Contact / Not a contact" indicator was not being updated when an user was added/removed as contact --- src/app/profile/view.nim | 21 ++++++++++++-------- ui/app/AppLayouts/Chat/ChatColumn/TopBar.qml | 1 + ui/shared/status/StatusChatInfo.qml | 16 ++++++++++++++- ui/shared/status/StatusChatInfoButton.qml | 2 ++ 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/app/profile/view.nim b/src/app/profile/view.nim index 41d83899df..2b6a773ff2 100644 --- a/src/app/profile/view.nim +++ b/src/app/profile/view.nim @@ -277,8 +277,11 @@ QtObject: ) self.contactToAddChanged() - proc addContact*(self: ProfileView, pk: string): string {.slot.} = - return self.status.contacts.addContact(pk) + proc contactChanged(self: ProfileView, publicKey: string, isAdded: bool) {.signal.} + + proc addContact*(self: ProfileView, publicKey: string): string {.slot.} = + result = self.status.contacts.addContact(publicKey) + self.contactChanged(publicKey, true) proc changeContactNickname*(self: ProfileView, publicKey: string, nickname: string) {.slot.} = var nicknameToSet = nickname @@ -286,11 +289,13 @@ QtObject: nicknameToSet = DELETE_CONTACT discard self.status.contacts.addContact(publicKey, nicknameToSet) - proc unblockContact*(self: ProfileView, id: string) {.slot.} = - discard self.status.contacts.unblockContact(id) + proc unblockContact*(self: ProfileView, publicKey: string) {.slot.} = + discard self.status.contacts.unblockContact(publicKey) - proc blockContact*(self: ProfileView, id: string): string {.slot.} = - return self.status.contacts.blockContact(id) + proc blockContact*(self: ProfileView, publicKey: string): string {.slot.} = + return self.status.contacts.blockContact(publicKey) + + proc removeContact*(self: ProfileView, publicKey: string) {.slot.} = + self.status.contacts.removeContact(publicKey) + self.contactChanged(publicKey, false) - proc removeContact*(self: ProfileView, id: string) {.slot.} = - self.status.contacts.removeContact(id) diff --git a/ui/app/AppLayouts/Chat/ChatColumn/TopBar.qml b/ui/app/AppLayouts/Chat/ChatColumn/TopBar.qml index dff4135dbb..327e93608e 100644 --- a/ui/app/AppLayouts/Chat/ChatColumn/TopBar.qml +++ b/ui/app/AppLayouts/Chat/ChatColumn/TopBar.qml @@ -28,6 +28,7 @@ Rectangle { Component { id: chatInfoButton StatusChatInfoButton { + chatId: chatsModel.activeChannel.id chatName: chatsModel.activeChannel.name chatType: chatsModel.activeChannel.chatType identicon: chatsModel.activeChannel.identicon diff --git a/ui/shared/status/StatusChatInfo.qml b/ui/shared/status/StatusChatInfo.qml index 9859505b41..03c06b7b79 100644 --- a/ui/shared/status/StatusChatInfo.qml +++ b/ui/shared/status/StatusChatInfo.qml @@ -7,6 +7,7 @@ import "../../shared/status" Item { id: root + property string chatId property string chatName property int chatType property string identicon @@ -48,6 +49,19 @@ Item { font.pixelSize: 15 } + + Connections { + target: profileModel + onContactChanged: { + if(root.chatId === publicKey){ + // Hack warning: Triggering reload to avoid changing the current text binding + var tmp = chatId; + chatId = ""; + chatId = tmp; + } + } + } + StyledText { id: chatInfo color: Style.current.darkGrey @@ -55,7 +69,7 @@ Item { switch(root.chatType){ //% "Public chat" case Constants.chatTypePublic: return qsTrId("public-chat") - case Constants.chatTypeOneToOne: return (profileModel.isAdded(root.chatName) ? + case Constants.chatTypeOneToOne: return (profileModel.isAdded(root.chatId) ? //% "Contact" qsTrId("chat-is-a-contact") : //% "Not a contact" diff --git a/ui/shared/status/StatusChatInfoButton.qml b/ui/shared/status/StatusChatInfoButton.qml index 0d756b2e6e..f37501d44f 100644 --- a/ui/shared/status/StatusChatInfoButton.qml +++ b/ui/shared/status/StatusChatInfoButton.qml @@ -7,6 +7,7 @@ import "../../shared/status" Button { id: control + property string chatId property string chatName property int chatType property string identicon @@ -20,6 +21,7 @@ Button { contentItem: StatusChatInfo { id: content + chatId: control.chatId chatName: control.chatName chatType: control.chatType identicon: control.identicon