From 8acb3c386aaf370daacc192768ffe6b80e7c29f4 Mon Sep 17 00:00:00 2001 From: Michal Iskierko Date: Fri, 1 Apr 2022 18:14:48 +0200 Subject: [PATCH] feature(desktop/general): Display mentions number on tray icon badge. Count all mentions from all chats and communities. Send it to notifications object. Issue #4922 --- Makefile | 2 +- src/app/core/notifications/notifications_manager.nim | 6 ++++++ src/app/global/global_events.nim | 6 ++++-- src/app/modules/main/io_interface.nim | 3 +++ src/app/modules/main/module.nim | 7 +++++-- src/app/modules/main/view.nim | 5 +++++ src/app/modules/shared_models/section_model.nim | 11 ++++++++++- 7 files changed, 34 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 52e4b070cc..6eae5656ea 100644 --- a/Makefile +++ b/Makefile @@ -137,7 +137,7 @@ ifneq ($(detected_OS),Windows) QT5_LIBDIR := $(QTDIR)/lib # some manually installed Qt5 instances have wrong paths in their *.pc files, so we pass the right one to the linker here ifeq ($(detected_OS),Darwin) - NIM_PARAMS += -L:"-framework Foundation -framework Security -framework IOKit -framework CoreServices -framework LocalAuthentication" + NIM_PARAMS += -L:"-framework Foundation -framework AppKit -framework Security -framework IOKit -framework CoreServices -framework LocalAuthentication" # Fix for failures due to 'can't allocate code signature data for' NIM_PARAMS += --passL:"-headerpad_max_install_names" NIM_PARAMS += --passL:"-F$(QT5_LIBDIR)" diff --git a/src/app/core/notifications/notifications_manager.nim b/src/app/core/notifications/notifications_manager.nim index b7414f3ccb..da68c0afca 100644 --- a/src/app/core/notifications/notifications_manager.nim +++ b/src/app/core/notifications/notifications_manager.nim @@ -79,6 +79,9 @@ QtObject: self, "onMyRequestToJoinCommunityAcccepted(QString, QString, QString)", 2) signalConnect(singletonInstance.globalEvents, "myRequestToJoinCommunityRejected(QString, QString, QString)", self, "onMyRequestToJoinCommunityRejected(QString, QString, QString)", 2) + signalConnect(singletonInstance.globalEvents, "meMentionedIconBadgeNotification(int)", + self, "onMeMentionedIconBadgeNotification(int)", 2) + self.notificationSetUp = true proc showOSNotification(self: NotificationsManager, title: string, message: string, identifier: string) = @@ -148,6 +151,9 @@ QtObject: sectionId: sectionId) self.processNotification(title, message, details) + proc onMeMentionedIconBadgeNotification(self: NotificationsManager, allMentions: int) {.slot.} = + self.osNotification.showIconBadgeNotification(allMentions) + proc notificationCheck(self: NotificationsManager, title: string, message: string, details: NotificationDetails, notificationWay: string) = var data = NotificationArgs(title: title, message: message, details: details) diff --git a/src/app/global/global_events.nim b/src/app/global/global_events.nim index 5a07c6825d..e156f9780d 100644 --- a/src/app/global/global_events.nim +++ b/src/app/global/global_events.nim @@ -27,6 +27,8 @@ QtObject: proc myRequestToJoinCommunityAcccepted*(self: GlobalEvents, title: string, message: string, sectionId: string) {.signal.} - + proc myRequestToJoinCommunityRejected*(self: GlobalEvents, title: string, message: string, - sectionId: string) {.signal.} \ No newline at end of file + sectionId: string) {.signal.} + + proc meMentionedIconBadgeNotification*(self: GlobalEvents, allMentions: int) {.signal.} \ No newline at end of file diff --git a/src/app/modules/main/io_interface.nim b/src/app/modules/main/io_interface.nim index 7923300200..d54596ee30 100644 --- a/src/app/modules/main/io_interface.nim +++ b/src/app/modules/main/io_interface.nim @@ -132,6 +132,9 @@ method newCommunityMembershipRequestReceived*(self: AccessInterface, membershipR {.base.} = raise newException(ValueError, "No implementation available") +method meMentionedCountChanged*(self: AccessInterface, allMentions: int) {.base.} = + raise newException(ValueError, "No implementation available") + method onNetworkConnected*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index 95c31f8f44..664722ddbd 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -539,7 +539,7 @@ method onActiveChatChange*[T](self: Module[T], sectionId: string, chatId: string method onNotificationsUpdated[T](self: Module[T], sectionId: string, sectionHasUnreadMessages: bool, sectionNotificationCount: int) = - self.view.model().udpateNotifications(sectionId, sectionHasUnreadMessages, sectionNotificationCount) + self.view.model().updateNotifications(sectionId, sectionHasUnreadMessages, sectionNotificationCount) method onNetworkConnected[T](self: Module[T]) = self.view.setConnected(true) @@ -672,7 +672,7 @@ method calculateProfileSectionHasNotification*[T](self: Module[T]): bool = return not self.controller.isMnemonicBackedUp() method mnemonicBackedUp*[T](self: Module[T]) = - self.view.model().udpateNotifications( + self.view.model().updateNotifications( conf.SETTINGS_SECTION_ID, self.calculateProfileSectionHasNotification(), notificationsCount = 0) @@ -694,3 +694,6 @@ method newCommunityMembershipRequestReceived*[T](self: Module[T], membershipRequ let community = self.controller.getCommunityById(membershipRequest.communityId) singletonInstance.globalEvents.newCommunityMembershipRequestNotification("New membership request", fmt "{contactName} asks to join {community.name}", community.id) + +method meMentionedCountChanged*[T](self: Module[T], allMentions: int) = + singletonInstance.globalEvents.meMentionedIconBadgeNotification(allMentions) diff --git a/src/app/modules/main/view.nim b/src/app/modules/main/view.nim index 76893f0c63..41b67d41fb 100644 --- a/src/app/modules/main/view.nim +++ b/src/app/modules/main/view.nim @@ -38,6 +38,8 @@ QtObject: result.activeSectionVariant = newQVariant(result.activeSection) result.chatSearchModel = chat_search_model.newModel() result.chatSearchModelVariant = newQVariant(result.chatSearchModel) + signalConnect(result.model, "notificationsCountChanged()", result, + "onNotificationsCountChanged()", 2) proc load*(self: View) = # In some point, here, we will setup some exposed main module related things. @@ -72,6 +74,9 @@ QtObject: proc rebuildChatSearchModel*(self: View) {.slot.} = self.delegate.rebuildChatSearchModel() + proc onNotificationsCountChanged*(self: View) {.slot.} = + self.delegate.meMentionedCountChanged(self.model.allMentionsCount()) + QtProperty[QVariant] chatSearchModel: read = getChatSearchModel notify = chatSearchModelChanged diff --git a/src/app/modules/shared_models/section_model.nim b/src/app/modules/shared_models/section_model.nim index 9a6d40b976..d68098031a 100644 --- a/src/app/modules/shared_models/section_model.nim +++ b/src/app/modules/shared_models/section_model.nim @@ -248,6 +248,8 @@ QtObject: proc sectionVisibilityUpdated*(self: SectionModel) {.signal.} + proc notificationsCountChanged*(self: SectionModel) {.signal.} + proc enableDisableSection(self: SectionModel, sectionType: SectionType, value: bool) = if(sectionType != SectionType.Community): for i in 0 ..< self.items.len: @@ -280,13 +282,20 @@ QtObject: proc disableSection*(self: SectionModel, sectionType: SectionType) = self.enableDisableSection(sectionType, false) - proc udpateNotifications*(self: SectionModel, id: string, hasNotification: bool, notificationsCount: int) = + # Count all mentions from all chat&community sections + proc allMentionsCount*(self: SectionModel): int = + for item in self.items: + if item.sectionType == SectionType.Chat or item.sectionType == SectionType.Community: + result += item.notificationsCount + + proc updateNotifications*(self: SectionModel, id: string, hasNotification: bool, notificationsCount: int) = for i in 0 ..< self.items.len: if(self.items[i].id == id): let index = self.createIndex(i, 0, nil) self.items[i].hasNotification = hasNotification self.items[i].notificationsCount = notificationsCount self.dataChanged(index, index, @[ModelRole.HasNotification.int, ModelRole.NotificationsCount.int]) + self.notificationsCountChanged() return proc getSectionNameById*(self: SectionModel, sectionId: string): string {.slot.} =