From 5592335b2fe55cab64e89a901a5f9413a61b9c10 Mon Sep 17 00:00:00 2001 From: Boris Melnik Date: Tue, 21 Mar 2023 19:27:40 +0300 Subject: [PATCH] fix(chat_section): Open Chat section before creating or switching to one-to-one chat Fixes: #9880 --- src/app/modules/main/chat_section/controller.nim | 11 +++++------ src/app/modules/main/chat_section/module.nim | 11 +++++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/app/modules/main/chat_section/controller.nim b/src/app/modules/main/chat_section/controller.nim index 8b330bafed..dec16c3e8a 100644 --- a/src/app/modules/main/chat_section/controller.nim +++ b/src/app/modules/main/chat_section/controller.nim @@ -333,12 +333,11 @@ proc init*(self: Controller) = if (self.sectionId != args.sectionId): return self.delegate.makeChatWithIdActive(args.chatId) - - self.events.on(SIGNAL_CHAT_SWITCH_TO_OR_CREATE_1_1_CHAT) do(e:Args): - let args = ChatExtArgs(e) - if (self.isCommunitySection): - return - self.delegate.createOneToOneChat(args.communityId, args.chatId, args.ensName) + + if (not self.isCommunitySection): + self.events.on(SIGNAL_CHAT_SWITCH_TO_OR_CREATE_1_1_CHAT) do(e:Args): + let args = ChatExtArgs(e) + self.delegate.createOneToOneChat(args.communityId, args.chatId, args.ensName) self.events.on(SIGNAL_CONTACTS_STATUS_UPDATED) do(e: Args): let args = ContactsStatusUpdatedArgs(e) diff --git a/src/app/modules/main/chat_section/module.nim b/src/app/modules/main/chat_section/module.nim index c21415f0c0..da96c41a86 100644 --- a/src/app/modules/main/chat_section/module.nim +++ b/src/app/modules/main/chat_section/module.nim @@ -708,7 +708,10 @@ method onCommunityChannelEdited*(self: Module, chat: ChatDto) = method switchToOrCreateOneToOneChat*(self: Module, chatId: string) = # One To One chat is available only in the `Chat` section - if(self.controller.getMySectionId() != singletonInstance.userProfile.getPubKey()): + if (self.controller.getMySectionId() == singletonInstance.userProfile.getPubKey()) and (self.delegate.getActiveSectionId() != self.controller.getMySectionId()): + self.delegate.setActiveSectionById(self.controller.getMySectionId()) + # if its not `Chat` section - skip + else: return if(self.chatContentModules.hasKey(chatId)): @@ -719,9 +722,9 @@ method switchToOrCreateOneToOneChat*(self: Module, chatId: string) = method createOneToOneChat*(self: Module, communityID: string, chatId: string, ensName: string) = if(self.controller.isCommunity()): - # initiate chat creation in the `Chat` seciton module. - self.controller.switchToOrCreateOneToOneChat(chatId, ensName) - return + # initiate chat creation in the `Chat` seciton module. + self.controller.switchToOrCreateOneToOneChat(chatId, ensName) + return # Adding this call here we have the same as we had before (didn't inspect what are all cases when this # `createOneToOneChat` is called), but I am sure that after checking all cases and inspecting them, this can be improved.