From ceb810e63d29f4947a10709a8e6bf37019f4a100 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 31 May 2023 15:09:37 -0400 Subject: [PATCH] fix(contacts): fix inconsistency when banning or unbanning contact Fixes #10501 The problem was that didn't have access to the updated contact from status-go after banning or unbanning, so we just changed the banned property, but there is more that gets changed in the backend, like `removed` being set to `true` as well. With this fix, when you unban someone, you go back to a fresh start, as **non** contact, so you need to send a request again. That was the state you got if you restarted the app, so "re-sync" the state with status-go. Another issue was on the frontend (QML). When banned, and after restarting to get the right state, the unban button would be disabled and the Add contact request button would show, which is not good. We only want to send requests when unbanned. --- src/app_service/service/contacts/service.nim | 7 +++---- ui/app/AppLayouts/Chat/stores/RootStore.qml | 2 +- ui/app/AppLayouts/Chat/views/ChatContentView.qml | 14 ++++++++++---- ui/app/AppLayouts/Chat/views/ChatMessagesView.qml | 3 ++- vendor/status-go | 2 +- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/app_service/service/contacts/service.nim b/src/app_service/service/contacts/service.nim index 70b3fdfc38..5d668b5e8c 100644 --- a/src/app_service/service/contacts/service.nim +++ b/src/app_service/service/contacts/service.nim @@ -516,12 +516,12 @@ QtObject: var contact = self.getContactById(publicKey) let response = status_contacts.unblockContact(contact.id) + # TODO there are chat updates too. We need to send them to the chat service if not response.error.isNil: error "error unblocking contact ", msg = response.error.message return - contact.blocked = false - self.saveContact(contact) + self.parseContactsResponse(response) self.events.emit(SIGNAL_CONTACT_UNBLOCKED, ContactArgs(contactId: contact.id)) proc blockContact*(self: Service, publicKey: string) = @@ -532,8 +532,7 @@ QtObject: error "error blocking contact ", msg = response.error.message return - contact.blocked = true - self.saveContact(contact) + self.parseContactsResponse(response) self.events.emit(SIGNAL_CONTACT_BLOCKED, ContactArgs(contactId: contact.id)) proc removeContact*(self: Service, publicKey: string) = diff --git a/ui/app/AppLayouts/Chat/stores/RootStore.qml b/ui/app/AppLayouts/Chat/stores/RootStore.qml index b387282ed6..9c2e890536 100644 --- a/ui/app/AppLayouts/Chat/stores/RootStore.qml +++ b/ui/app/AppLayouts/Chat/stores/RootStore.qml @@ -699,7 +699,7 @@ QtObject { readonly property bool isUserAllowedToSendMessage: { if (_d.activeChatType === Constants.chatType.oneToOne && _d.oneToOneChatContact) { - return _d.oneToOneChatContact.contactRequestState == Constants.ContactRequestState.Mutual + return _d.oneToOneChatContact.contactRequestState === Constants.ContactRequestState.Mutual } else if(_d.activeChatType === Constants.chatType.privateGroupChat) { return _d.amIMember diff --git a/ui/app/AppLayouts/Chat/views/ChatContentView.qml b/ui/app/AppLayouts/Chat/views/ChatContentView.qml index 1e30abad2f..276c28946c 100644 --- a/ui/app/AppLayouts/Chat/views/ChatContentView.qml +++ b/ui/app/AppLayouts/Chat/views/ChatContentView.qml @@ -77,6 +77,8 @@ ColumnLayout { QtObject { id: d + readonly property string blockedText: qsTr("This user has been blocked.") + function showReplyArea(messageId) { let obj = messageStore.getMessageByIdAsJson(messageId) if (!obj) { @@ -109,6 +111,7 @@ ColumnLayout { stickersLoaded: root.stickersLoaded chatId: root.chatId isOneToOne: root.chatType === Constants.chatType.oneToOne + isContactBlocked: root.isBlocked isChatBlocked: root.isBlocked || !root.isUserAllowedToSendMessage channelEmoji: !chatContentModule ? "" : (chatContentModule.chatDetails.emoji || "") isActiveChannel: root.isActiveChannel @@ -158,14 +161,17 @@ ColumnLayout { anchors.fill: parent anchors.margins: Style.current.smallPadding - enabled: root.rootStore.sectionDetails.joined && !root.rootStore.sectionDetails.amIBanned && - root.isUserAllowedToSendMessage + // We enable the component if the contact is blocked, because if we disable it, the `Unban` button + // becomes disabled. All the local components inside already disable themselves when blocked + enabled: root.isBlocked || + (root.rootStore.sectionDetails.joined && !root.rootStore.sectionDetails.amIBanned && + root.isUserAllowedToSendMessage) store: root.rootStore usersStore: root.usersStore textInput.text: inputAreaLoader.preservedText - textInput.placeholderText: root.chatInputPlaceholder + textInput.placeholderText: root.isBlocked ? d.blockedText : root.chatInputPlaceholder emojiPopup: root.emojiPopup stickersPopup: root.stickersPopup isContactBlocked: root.isBlocked @@ -176,7 +182,7 @@ ColumnLayout { Binding on chatInputPlaceholder { when: root.isBlocked - value: qsTr("This user has been blocked.") + value: d.blockedText } Binding on chatInputPlaceholder { diff --git a/ui/app/AppLayouts/Chat/views/ChatMessagesView.qml b/ui/app/AppLayouts/Chat/views/ChatMessagesView.qml index 208eb9d4de..e30da4ba41 100644 --- a/ui/app/AppLayouts/Chat/views/ChatMessagesView.qml +++ b/ui/app/AppLayouts/Chat/views/ChatMessagesView.qml @@ -36,6 +36,7 @@ Item { property string chatId: "" property bool stickersLoaded: false property alias chatLogView: chatLogView + property bool isContactBlocked: false property bool isChatBlocked: false property bool isOneToOne: false property bool isActiveChannel: false @@ -329,7 +330,7 @@ Item { } } header: { - if (root.isOneToOne && root.rootStore.oneToOneChatContact) { + if (!root.isContactBlocked && root.isOneToOne && root.rootStore.oneToOneChatContact) { switch (root.rootStore.oneToOneChatContact.contactRequestState) { case Constants.ContactRequestState.None: // no break case Constants.ContactRequestState.Dismissed: diff --git a/vendor/status-go b/vendor/status-go index a7df4ed388..3f00869e1f 160000 --- a/vendor/status-go +++ b/vendor/status-go @@ -1 +1 @@ -Subproject commit a7df4ed388e4d78653326ed7a35e72221e23a5d9 +Subproject commit 3f00869e1faed9fee17f6dfe500280c93d390284