diff --git a/src/app/modules/main/chat_section/module.nim b/src/app/modules/main/chat_section/module.nim index dbe5cf13e6..42a7991c4c 100644 --- a/src/app/modules/main/chat_section/module.nim +++ b/src/app/modules/main/chat_section/module.nim @@ -342,6 +342,13 @@ method getChatContentModule*(self: Module, chatId: string): QVariant = return self.chatContentModules[chatId].getModuleAsVariant() +proc updateParentNotifications(self: Module) = + var (sectionHasUnreadMessages, sectionNotificationCount) = self.view.chatsModel().getAllNotifications() + if(not self.controller.isCommunity()): + sectionNotificationCount += self.view.contactRequestsModel().getCount() + sectionHasUnreadMessages = sectionHasUnreadMessages or sectionNotificationCount > 0 + self.delegate.onNotificationsUpdated(self.controller.getMySectionId(), sectionHasUnreadMessages, sectionNotificationCount) + 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)) @@ -350,8 +357,7 @@ proc updateNotifications(self: Module, chatId: string, unviewedMessagesCount: in 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) + self.updateParentNotifications() method onActiveSectionChange*(self: Module, sectionId: string) = if(sectionId != self.controller.getMySectionId()): @@ -558,6 +564,7 @@ method acceptContactRequest*(self: Module, publicKey: string) = method onContactAccepted*(self: Module, publicKey: string) = self.view.contactRequestsModel().removeItemWithPubKey(publicKey) + self.updateParentNotifications() method acceptAllContactRequests*(self: Module) = let pubKeys = self.view.contactRequestsModel().getPublicKeys() @@ -569,6 +576,7 @@ method rejectContactRequest*(self: Module, publicKey: string) = method onContactRejected*(self: Module, publicKey: string) = self.view.contactRequestsModel().removeItemWithPubKey(publicKey) + self.updateParentNotifications() method rejectAllContactRequests*(self: Module) = let pubKeys = self.view.contactRequestsModel().getPublicKeys() @@ -593,6 +601,7 @@ method onContactDetailsUpdated*(self: Module, publicKey: string) = not self.view.contactRequestsModel().containsItemWithPubKey(publicKey)): let item = self.createItemFromPublicKey(publicKey) self.view.contactRequestsModel().addItem(item) + self.updateParentNotifications() let (chatName, chatImage, isIdenticon) = self.controller.getOneToOneChatNameAndImage(publicKey) self.view.chatsModel().updateItemDetails(publicKey, chatName, chatImage, isIdenticon) diff --git a/src/app/modules/main/controller.nim b/src/app/modules/main/controller.nim index 5442469fae..962bc1d67c 100644 --- a/src/app/modules/main/controller.nim +++ b/src/app/modules/main/controller.nim @@ -243,6 +243,9 @@ method setUserStatus*(self: Controller, status: bool) = method getContact*(self: Controller, id: string): ContactsDto = return self.contactsService.getContactById(id) +method getContacts*(self: Controller): seq[ContactsDto] = + return self.contactsService.getContacts() + method getContactNameAndImage*(self: Controller, contactId: string): tuple[name: string, image: string, isIdenticon: bool] = return self.contactsService.getContactNameAndImage(contactId) diff --git a/src/app/modules/main/controller_interface.nim b/src/app/modules/main/controller_interface.nim index 6d2a3667cb..76e7eb9c35 100644 --- a/src/app/modules/main/controller_interface.nim +++ b/src/app/modules/main/controller_interface.nim @@ -41,6 +41,9 @@ method setUserStatus*(self: AccessInterface, status: bool) {.base.} = method getContact*(self: AccessInterface, id: string): ContactsDto {.base.} = raise newException(ValueError, "No implementation available") +method getContacts*(self: AccessInterface): seq[ContactsDto] {.base.} = + raise newException(ValueError, "No implementation available") + method getContactNameAndImage*(self: AccessInterface, contactId: string): tuple[name: string, image: string, isIdenticon: bool] {.base.} = raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index 34ca355a64..d46f869275 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -256,9 +256,10 @@ method load*[T]( var activeSectionId = singletonInstance.localAccountSensitiveSettings.getActiveSection() # Chat Section + let receivedContactRequests = self.controller.getContacts().filter(x => x.requestReceived() and not x.isContact() and not x.isBlocked()) let (unviewedCount, mentionsCount) = self.controller.getNumOfNotificaitonsForChat() - let hasNotification = unviewedCount > 0 or mentionsCount > 0 - let notificationsCount = mentionsCount + let notificationsCount = mentionsCount + receivedContactRequests.len + let hasNotification = unviewedCount > 0 or notificationsCount > 0 let chatSectionItem = initItem(conf.CHAT_SECTION_ID, SectionType.Chat, conf.CHAT_SECTION_NAME, amISectionAdmin = false, description = "", diff --git a/src/app/modules/shared_models/contacts_model.nim b/src/app/modules/shared_models/contacts_model.nim index d6e124e9ce..5191c20bae 100644 --- a/src/app/modules/shared_models/contacts_model.nim +++ b/src/app/modules/shared_models/contacts_model.nim @@ -27,7 +27,7 @@ QtObject: result.setup proc countChanged(self: Model) {.signal.} - proc getCount(self: Model): int {.slot.} = + proc getCount*(self: Model): int {.slot.} = self.items.len QtProperty[int] count: read = getCount diff --git a/src/app_service/service/contacts/service.nim b/src/app_service/service/contacts/service.nim index c72c30145c..6ad39c996c 100644 --- a/src/app_service/service/contacts/service.nim +++ b/src/app_service/service/contacts/service.nim @@ -141,13 +141,13 @@ QtObject: return toSeq(self.contacts.values) proc getAddedContacts*(self: Service): seq[ContactsDto] = - return self.getContacts().filter(x => x.added) + return self.getContacts().filter(x => x.isContact()) proc getBlockedContacts*(self: Service): seq[ContactsDto] = - return self.getContacts().filter(x => x.blocked) + return self.getContacts().filter(x => x.isBlocked()) proc getContactsWhoAddedMe*(self: Service): seq[ContactsDto] = - return self.getContacts().filter(x => x.hasAddedUs) + return self.getContacts().filter(x => x.requestReceived()) proc fetchContact(self: Service, id: string): ContactsDto = try: