From 1735d7e75a728023b9a3bb318ce404d6af5fde9a Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Tue, 17 Dec 2024 15:13:09 -0500 Subject: [PATCH] fix(block): remove chat and messages when blocking a contact (#16889) Fixes #16640 This makes it so that when you block a contact, it now also removes the chat and the messages as expected by the requirements and as Mobile does. To do so, I use the same API as mobile instead of the forked desktop one. I removed the desktop one as it is no longer needed (see status-go PR) I also fixed an issue when unblocking where it would send a double toast messages with one saying you "removed the contact", but it was already removed. --- src/app/modules/main/chat_section/module.nim | 3 ++- src/app_service/service/chat/service.nim | 8 -------- src/app_service/service/contacts/service.nim | 9 +++------ src/backend/contacts.nim | 2 +- vendor/status-go | 2 +- 5 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/app/modules/main/chat_section/module.nim b/src/app/modules/main/chat_section/module.nim index 34c0d8d6ff..26cd3c29c9 100644 --- a/src/app/modules/main/chat_section/module.nim +++ b/src/app/modules/main/chat_section/module.nim @@ -882,7 +882,7 @@ method onCategoryNameChanged*(self: Module, category: Category) = self.view.chatsModel().renameCategory(category.id, category.name) method onCommunityChannelDeletedOrChatLeft*(self: Module, chatId: string) = - if(not self.chatContentModules.contains(chatId)): + if not self.chatContentModules.contains(chatId): return self.view.chatsModel().removeItemById(chatId) self.removeSubmodule(chatId) @@ -1197,6 +1197,7 @@ method blockContact*(self: Module, publicKey: string) = method onContactBlocked*(self: Module, publicKey: string) = self.view.contactRequestsModel().removeItemById(publicKey) self.view.chatsModel().changeBlockedOnItemById(publicKey, blocked=true) + self.onCommunityChannelDeletedOrChatLeft(publicKey) method onContactUnblocked*(self: Module, publicKey: string) = self.view.chatsModel().changeBlockedOnItemById(publicKey, blocked=false) diff --git a/src/app_service/service/chat/service.nim b/src/app_service/service/chat/service.nim index 3ec1d2b8e7..708da8fe12 100644 --- a/src/app_service/service/chat/service.nim +++ b/src/app_service/service/chat/service.nim @@ -84,9 +84,6 @@ type role*: MemberRole joined*: bool - RpcResponseArgs* = ref object of Args - response*: RpcResponse[JsonNode] - CheckChannelPermissionsResponseArgs* = ref object of Args communityId*: string chatId*: string @@ -120,7 +117,6 @@ const SIGNAL_CHAT_MEMBER_UPDATED* = "chatMemberUpdated" const SIGNAL_CHAT_SWITCH_TO_OR_CREATE_1_1_CHAT* = "switchToOrCreateOneToOneChat" const SIGNAL_CHAT_ADDED_OR_UPDATED* = "chatAddedOrUpdated" const SIGNAL_CHAT_CREATED* = "chatCreated" -const SIGNAL_CHAT_REQUEST_UPDATE_AFTER_SEND* = "chatRequestUpdateAfterSend" const SIGNAL_CHECK_CHANNEL_PERMISSIONS_RESPONSE* = "checkChannelPermissionsResponse" const SIGNAL_CHECK_ALL_CHANNELS_PERMISSIONS_RESPONSE* = "checkAllChannelsPermissionsResponse" const SIGNAL_CHECK_ALL_CHANNELS_PERMISSIONS_FAILED* = "checkAllChannelsPermissionsFailed" @@ -183,10 +179,6 @@ QtObject: for clearedHistoryDto in receivedData.clearedHistories: self.events.emit(SIGNAL_CHAT_HISTORY_CLEARED, ChatArgs(chatId: clearedHistoryDto.chatId)) - self.events.on(SIGNAL_CHAT_REQUEST_UPDATE_AFTER_SEND) do(e: Args): - var args = RpcResponseArgs(e) - discard self.processMessengerResponse(args.response) - proc asyncGetActiveChats*(self: Service) = let arg = AsyncGetActiveChatsTaskArg( tptr: asyncGetActiveChatsTask, diff --git a/src/app_service/service/contacts/service.nim b/src/app_service/service/contacts/service.nim index 37b5b00cdf..7a32927fc2 100644 --- a/src/app_service/service/contacts/service.nim +++ b/src/app_service/service/contacts/service.nim @@ -52,9 +52,6 @@ type publicKey*: string ok*: bool - RpcResponseArgs* = ref object of Args - response*: RpcResponse[JsonNode] - AppendChatMessagesArgs* = ref object of Args chatId*: string messages*: JsonNode @@ -395,9 +392,9 @@ QtObject: if self.contacts.hasKey(publicKey): if self.contacts[publicKey].dto.added and not self.contacts[publicKey].dto.removed and contact.added and not contact.removed: signal = SIGNAL_CONTACT_UPDATED - if contact.removed: - singletonInstance.globalEvents.showContactRemoved("Contact removed", fmt "You removed {contact.displayName} as a contact", contact.id) - signal = SIGNAL_CONTACT_REMOVED + if contact.removed and not self.contacts[publicKey].dto.removed: + singletonInstance.globalEvents.showContactRemoved("Contact removed", fmt "You removed {contact.displayName} as a contact", contact.id) + signal = SIGNAL_CONTACT_REMOVED self.contacts[publicKey] = self.constructContactDetails(contact) self.events.emit(signal, ContactArgs(contactId: publicKey)) diff --git a/src/backend/contacts.nim b/src/backend/contacts.nim index 74abaf4eaf..d0b3531189 100644 --- a/src/backend/contacts.nim +++ b/src/backend/contacts.nim @@ -9,7 +9,7 @@ proc getContacts*(): RpcResponse[JsonNode] = result = callPrivateRPC("contacts".prefix, payload) proc blockContact*(id: string): RpcResponse[JsonNode] = - result = callPrivateRPC("blockContactDesktop".prefix, %* [id]) + result = callPrivateRPC("blockContact".prefix, %* [id]) proc unblockContact*(id: string): RpcResponse[JsonNode] = result = callPrivateRPC("unblockContact".prefix, %* [id]) diff --git a/vendor/status-go b/vendor/status-go index c27c773c27..d291204473 160000 --- a/vendor/status-go +++ b/vendor/status-go @@ -1 +1 @@ -Subproject commit c27c773c27a10d0dd7742d324455ca7143829065 +Subproject commit d291204473d2dcdb27062f017ffe9966463d4818