@@ -2,7 +2,7 @@ import { getPersonBySocialId, formatName } from '@hcengineering/contact'
2
2
import { Ref , TxOperations } from '@hcengineering/core'
3
3
import notification , { DocNotifyContext , CommonInboxNotification , ActivityInboxNotification , InboxNotification } from '@hcengineering/notification'
4
4
import { IntlString , addEventListener , translate } from '@hcengineering/platform'
5
- import { getClient } from '@hcengineering/presentation'
5
+ import { getClient , createNotificationsQuery } from '@hcengineering/presentation'
6
6
import { location } from '@hcengineering/ui'
7
7
import workbench , { workbenchId } from '@hcengineering/workbench'
8
8
import desktopPreferences , { defaultNotificationPreference } from '@hcengineering/desktop-preferences'
@@ -13,6 +13,8 @@ import { IPCMainExposed } from './types'
13
13
14
14
let client : TxOperations
15
15
16
+ const notificationsQuery = createNotificationsQuery ( )
17
+
16
18
async function hydrateNotificationAsYouCan ( lastNotification : InboxNotification ) : Promise < { title : string , body : string } | undefined > {
17
19
// Let's try to do our best and figure out from who we have an notification
18
20
@@ -114,13 +116,19 @@ export function configureNotifications (): void {
114
116
// because we generate them on a client
115
117
let initTimestamp = 0
116
118
const notificationHistory = new Map < string , number > ( )
119
+ let newUnreadNotifications = 0
117
120
118
121
addEventListener ( workbench . event . NotifyConnection , async ( ) => {
119
122
client = getClient ( )
120
123
const electronAPI : IPCMainExposed = ( window as any ) . electron
121
124
122
125
const inboxClient = InboxNotificationsClientImpl . getClient ( )
123
126
127
+ notificationsQuery . query ( { read : false , limit : 1000 } , res => {
128
+ newUnreadNotifications = res . getResult ( ) . length
129
+ electronAPI . setBadge ( prevUnViewdNotificationsCount + newUnreadNotifications )
130
+ } )
131
+
124
132
async function handleNotifications ( notificationsByContext : Map < Ref < DocNotifyContext > , InboxNotification [ ] > ) : Promise < void > {
125
133
const inboxData = await getDisplayInboxData ( notificationsByContext )
126
134
@@ -138,7 +146,7 @@ export function configureNotifications (): void {
138
146
139
147
if ( prevUnViewdNotificationsCount !== unViewedNotifications . length ) {
140
148
if ( preferences . showUnreadCounter ) {
141
- electronAPI . setBadge ( unViewedNotifications . length )
149
+ electronAPI . setBadge ( unViewedNotifications . length + newUnreadNotifications )
142
150
}
143
151
if ( preferences . bounceAppIcon ) {
144
152
electronAPI . dockBounce ( )
@@ -179,7 +187,7 @@ export function configureNotifications (): void {
179
187
electronAPI . setBadge ( 0 )
180
188
}
181
189
if ( ! preferences . showUnreadCounter && newPreferences . showUnreadCounter ) {
182
- electronAPI . setBadge ( prevUnViewdNotificationsCount )
190
+ electronAPI . setBadge ( prevUnViewdNotificationsCount + newUnreadNotifications )
183
191
}
184
192
preferences = newPreferences
185
193
} )
0 commit comments