diff --git a/src/app/modules/main/chat_section/module.nim b/src/app/modules/main/chat_section/module.nim index ac30f78db0..fd202cbbf4 100644 --- a/src/app/modules/main/chat_section/module.nim +++ b/src/app/modules/main/chat_section/module.nim @@ -331,10 +331,22 @@ method getChatContentModule*(self: Module, chatId: string): QVariant = return self.chatContentModules[chatId].getModuleAsVariant() +proc updateNotifications(self: Module, chatId: string, unviewedMessagesCount: int, unviewedMentionsCount: int) = + let hasUnreadMessages = unviewedMessagesCount > 0 + # update model of this module (appropriate chat from the chats list (chats model)) + self.view.chatsModel().updateNotificationsForItemOrSubItemById(chatId, hasUnreadMessages, unviewedMentionsCount) + # update child module + if (self.chatContentModules.contains(chatId)): + self.chatContentModules[chatId].onNotificationsUpdated(hasUnreadMessages, unviewedMentionsCount) + # update parent module + let (sectionHasUnreadMessages, sectionNotificationCount) = self.view.chatsModel().getAllNotifications() + self.delegate.onNotificationsUpdated(self.controller.getMySectionId(), sectionHasUnreadMessages, sectionNotificationCount) + method onActiveSectionChange*(self: Module, sectionId: string) = if(sectionId != self.controller.getMySectionId()): return + self.updateNotifications(self.controller.getActiveChatId(), unviewedMessagesCount=0, unviewedMentionsCount=0) self.delegate.onActiveChatChange(self.controller.getMySectionId(), self.controller.getActiveChatId()) method createPublicChat*(self: Module, chatId: string) = @@ -456,17 +468,6 @@ method createOneToOneChat*(self: Module, chatId: string, ensName: string) = self.controller.createOneToOneChat(chatId, ensName) -proc updateNotifications(self: Module, chatId: string, unviewedMessagesCount: int, unviewedMentionsCount: int) = - let hasUnreadMessages = unviewedMessagesCount > 0 - # update model of this module (appropriate chat from the chats list (chats model)) - self.view.chatsModel().updateNotificationsForItemOrSubItemById(chatId, hasUnreadMessages, unviewedMentionsCount) - # update child module - if (self.chatContentModules.contains(chatId)): - self.chatContentModules[chatId].onNotificationsUpdated(hasUnreadMessages, unviewedMentionsCount) - # update parent module - let (sectionHasUnreadMessages, sectionNotificationCount) = self.view.chatsModel().getAllNotifications() - self.delegate.onNotificationsUpdated(self.controller.getMySectionId(), sectionHasUnreadMessages, sectionNotificationCount) - method leaveChat*(self: Module, chatId: string) = self.controller.leaveChat(chatId) @@ -537,11 +538,10 @@ method onContactDetailsUpdated*(self: Module, publicKey: string) = method onNewMessagesReceived*(self: Module, chatId: string, unviewedMessagesCount: int, unviewedMentionsCount: int, messages: seq[MessageDto]) = - let activeChatId = self.controller.getActiveChatId() - if(activeChatId == chatId): - self.controller.markAllMessagesRead(chatId) - else: - self.updateNotifications(chatId, unviewedMessagesCount, unviewedMentionsCount) + if(self.controller.getMySectionId() == self.delegate.getActiveSectionId() and + self.controller.getActiveChatId() == chatId): + return + self.updateNotifications(chatId, unviewedMessagesCount, unviewedMentionsCount) proc convertPubKeysToJson(self: Module, pubKeys: string): seq[string] = return map(parseJson(pubKeys).getElems(), proc(x:JsonNode):string = x.getStr) diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index 2135204fdc..260be45ceb 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -441,6 +441,9 @@ method emitStoringPasswordError*[T](self: Module[T], errorDescription: string) = method emitStoringPasswordSuccess*[T](self: Module[T]) = self.view.emitStoringPasswordSuccess() +method getActiveSectionId*[T](self: Module[T]): string = + return self.controller.getActiveSectionId() + method setActiveSection*[T](self: Module[T], item: SectionItem) = if(item.isEmpty()): echo "section is empty and cannot be made as active one" diff --git a/src/app/modules/main/private_interfaces/module_chat_section_delegate_interface.nim b/src/app/modules/main/private_interfaces/module_chat_section_delegate_interface.nim index 3537def809..796c63d8ec 100644 --- a/src/app/modules/main/private_interfaces/module_chat_section_delegate_interface.nim +++ b/src/app/modules/main/private_interfaces/module_chat_section_delegate_interface.nim @@ -9,4 +9,7 @@ method onActiveChatChange*(self: AccessInterface, sectionId: string, chatId: str method onNotificationsUpdated*(self: AccessInterface, sectionId: string, sectionHasUnreadMessages: bool, sectionNotificationCount: int) {.base.} = + raise newException(ValueError, "No implementation available") + +method getActiveSectionId*(self: AccessInterface): string {.base.} = raise newException(ValueError, "No implementation available") \ No newline at end of file