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
This commit is contained in:
parent
0b0fa51c89
commit
8acb3c386a
2
Makefile
2
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)"
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.}
|
||||
sectionId: string) {.signal.}
|
||||
|
||||
proc meMentionedIconBadgeNotification*(self: GlobalEvents, allMentions: int) {.signal.}
|
|
@ -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")
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.} =
|
||||
|
|
Loading…
Reference in New Issue