@@ -11,6 +11,7 @@ var NotificationsStore = Reflux.createStore({
1111
1212 init : function ( ) {
1313 this . _notifications = [ ] ;
14+ this . _previousNotifications = [ ] ;
1415 } ,
1516
1617 updateTrayIcon : function ( notifications ) {
@@ -21,6 +22,35 @@ var NotificationsStore = Reflux.createStore({
2122 }
2223 } ,
2324
25+ isNewNotification : function ( response ) {
26+ var self = this ;
27+ var playSound = SettingsStore . getSettings ( ) . playSound ;
28+
29+ if ( ! playSound ) { return ; }
30+
31+ // Check if notification is already in the store.
32+ var isNew = false ;
33+ _ . map ( response , function ( obj ) {
34+ if ( ! _ . contains ( self . _previousNotifications , obj . id ) ) {
35+ isNew = true ;
36+ }
37+ } ) ;
38+
39+ // Play Sound.
40+ if ( isNew ) {
41+ if ( playSound ) {
42+ var audio = new Audio ( 'sounds/digi.wav' ) ;
43+ audio . play ( ) ;
44+ }
45+ }
46+
47+ // Now Reset the previousNotifications array.
48+ self . _previousNotifications = [ ] ;
49+ _ . map ( response , function ( obj ) {
50+ self . _previousNotifications . push ( obj . id ) ;
51+ } ) ;
52+ } ,
53+
2454 onGetNotifications : function ( ) {
2555 var self = this ;
2656 var participating = SettingsStore . getSettings ( ) . participating ;
@@ -33,6 +63,7 @@ var NotificationsStore = Reflux.createStore({
3363 // Success - Do Something.
3464 Actions . getNotifications . completed ( response . body ) ;
3565 self . updateTrayIcon ( response . body ) ;
66+ self . isNewNotification ( response . body ) ;
3667 } else {
3768 // Error - Show messages.
3869 Actions . getNotifications . failed ( err ) ;
0 commit comments