@@ -6,6 +6,8 @@ import { Notification } from '../typesGithub';
6
6
7
7
import { AccountNotifications , SettingsState , AuthState } from '../types' ;
8
8
9
+ let markNotification : ( accounts : AuthState , id : string , hostname : string ) => Promise < void > ;
10
+
9
11
export const setTrayIconColor = ( notifications : AccountNotifications [ ] ) => {
10
12
const allNotificationsCount = notifications . reduce (
11
13
( memo , acc ) => memo + acc . notifications . length ,
@@ -19,16 +21,19 @@ export const triggerNativeNotifications = (
19
21
previousNotifications : AccountNotifications [ ] ,
20
22
newNotifications : AccountNotifications [ ] ,
21
23
settings : SettingsState ,
22
- accounts : AuthState
24
+ accounts : AuthState ,
25
+ markNotification_ ?: ( accounts : AuthState , id : string , hostname : string ) => Promise < void >
23
26
) => {
24
- const diffNotifications = newNotifications
27
+ markNotification ??= markNotification_ ;
28
+
29
+ const diff = newNotifications
25
30
. map ( ( account ) => {
26
31
const accountPreviousNotifications = previousNotifications . find (
27
32
( item ) => item . hostname === account . hostname
28
33
) ;
29
34
30
35
if ( ! accountPreviousNotifications ) {
31
- return account . notifications ;
36
+ return { hostname : account . hostname , notifications : account . notifications } ;
32
37
}
33
38
34
39
const accountPreviousNotificationsIds = accountPreviousNotifications . notifications . map (
@@ -39,9 +44,10 @@ export const triggerNativeNotifications = (
39
44
return ! accountPreviousNotificationsIds . includes ( `${ item . id } ` ) ;
40
45
} ) ;
41
46
42
- return accountNewNotifications ;
47
+ return { hostname : account . hostname , notifications : accountNewNotifications } ;
43
48
} )
44
- . reduce ( ( acc , val ) => acc . concat ( val ) , [ ] ) ;
49
+
50
+ const diffNotifications = diff . flatMap ( o => o . notifications )
45
51
46
52
setTrayIconColor ( newNotifications ) ;
47
53
@@ -55,13 +61,15 @@ export const triggerNativeNotifications = (
55
61
}
56
62
57
63
if ( settings . showNotifications ) {
58
- raiseNativeNotification ( diffNotifications , accounts ) ;
64
+ raiseNativeNotification ( diffNotifications , settings , accounts , diff [ 0 ] . hostname ) ;
59
65
}
60
66
} ;
61
67
62
68
export const raiseNativeNotification = (
63
69
notifications : Notification [ ] ,
64
- accounts : AuthState
70
+ settings : SettingsState ,
71
+ accounts : AuthState ,
72
+ hostname ?: string
65
73
) => {
66
74
let title : string ;
67
75
let body : string ;
@@ -84,6 +92,9 @@ export const raiseNativeNotification = (
84
92
if ( notifications . length === 1 ) {
85
93
remote . getCurrentWindow ( ) . hide ( ) ;
86
94
openInBrowser ( notifications [ 0 ] , accounts ) ;
95
+ if ( settings . markOnClick ) {
96
+ markNotification ?.( accounts , notifications [ 0 ] . id , hostname ) ;
97
+ }
87
98
} else {
88
99
reOpenWindow ( ) ;
89
100
}
0 commit comments