@@ -11,18 +11,39 @@ var NotificationsStore = Reflux.createStore({
11
11
12
12
init : function ( ) {
13
13
this . _notifications = [ ] ;
14
+ this . _previousNotifications = [ ] ;
14
15
} ,
15
16
16
17
updateTrayIcon : function ( notifications ) {
17
18
if ( notifications . length > 0 ) {
18
19
ipc . sendChannel ( 'update-icon' , 'TrayActive' ) ;
20
+ } else {
21
+ ipc . sendChannel ( 'update-icon' , 'TrayIdle' ) ;
22
+ }
23
+ } ,
19
24
25
+ isNewNotification : function ( response ) {
26
+ var self = this ;
27
+
28
+ // Check if notification is already in the store.
29
+ var isNew = false ;
30
+ _ . map ( response , function ( obj ) {
31
+ if ( ! _ . contains ( self . _previousNotifications , obj . id ) ) {
32
+ isNew = true ;
33
+ }
34
+ } ) ;
35
+
36
+ // Play Sound.
37
+ if ( isNew ) {
20
38
var audio = new Audio ( 'sounds/digi.wav' ) ;
21
39
audio . play ( ) ;
22
-
23
- } else {
24
- ipc . sendChannel ( 'update-icon' , 'TrayIdle' ) ;
25
40
}
41
+
42
+ // Now Reset the previousNotifications array.
43
+ self . _previousNotifications = [ ] ;
44
+ _ . map ( response , function ( obj ) {
45
+ self . _previousNotifications . push ( obj . id ) ;
46
+ } ) ;
26
47
} ,
27
48
28
49
onGetNotifications : function ( ) {
@@ -37,6 +58,7 @@ var NotificationsStore = Reflux.createStore({
37
58
// Success - Do Something.
38
59
Actions . getNotifications . completed ( response . body ) ;
39
60
self . updateTrayIcon ( response . body ) ;
61
+ self . isNewNotification ( response . body ) ;
40
62
} else {
41
63
// Error - Show messages.
42
64
Actions . getNotifications . failed ( err ) ;
0 commit comments