@@ -11,18 +11,39 @@ var NotificationsStore = Reflux.createStore({
1111
1212 init : function ( ) {
1313 this . _notifications = [ ] ;
14+ this . _previousNotifications = [ ] ;
1415 } ,
1516
1617 updateTrayIcon : function ( notifications ) {
1718 if ( notifications . length > 0 ) {
1819 ipc . sendChannel ( 'update-icon' , 'TrayActive' ) ;
20+ } else {
21+ ipc . sendChannel ( 'update-icon' , 'TrayIdle' ) ;
22+ }
23+ } ,
1924
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 ) {
2038 var audio = new Audio ( 'sounds/digi.wav' ) ;
2139 audio . play ( ) ;
22-
23- } else {
24- ipc . sendChannel ( 'update-icon' , 'TrayIdle' ) ;
2540 }
41+
42+ // Now Reset the previousNotifications array.
43+ self . _previousNotifications = [ ] ;
44+ _ . map ( response , function ( obj ) {
45+ self . _previousNotifications . push ( obj . id ) ;
46+ } ) ;
2647 } ,
2748
2849 onGetNotifications : function ( ) {
@@ -37,6 +58,7 @@ var NotificationsStore = Reflux.createStore({
3758 // Success - Do Something.
3859 Actions . getNotifications . completed ( response . body ) ;
3960 self . updateTrayIcon ( response . body ) ;
61+ self . isNewNotification ( response . body ) ;
4062 } else {
4163 // Error - Show messages.
4264 Actions . getNotifications . failed ( err ) ;
0 commit comments