@@ -10,11 +10,11 @@ var SoundNotificationStore = Reflux.createStore({
10
10
11
11
init : function ( ) {
12
12
this . _previousNotifications = [ ] ;
13
+ this . _audio = new Audio ( 'sounds/digi.wav' ) ;
13
14
} ,
14
15
15
16
playSound : function ( ) {
16
- var audio = new Audio ( 'sounds/digi.wav' ) ;
17
- audio . play ( ) ;
17
+ this . _audio . play ( ) ;
18
18
} ,
19
19
20
20
showNotification : function ( countNew , response , latestNotification ) {
@@ -40,32 +40,26 @@ var SoundNotificationStore = Reflux.createStore({
40
40
if ( ! playSound && ! showNotifications ) { return ; }
41
41
42
42
// Check if notification is already in the store.
43
- var countNew = 0 ;
44
- var latestNotification = { } ;
45
- _ . map ( response , function ( obj ) {
46
- if ( ! _ . contains ( self . _previousNotifications , obj . id ) ) {
47
- countNew ++ ;
48
- latestNotification = {
49
- full_name : obj . repository . full_name ,
50
- subject : obj . subject . title
51
- } ;
52
- }
43
+ var newNotifications = _ . filter ( response , function ( obj ) {
44
+ return ! _ . contains ( self . _previousNotifications , obj . id ) ;
53
45
} ) ;
54
46
55
47
// Play Sound / Show Notification.
56
- if ( countNew > 0 ) {
48
+ if ( newNotifications && newNotifications . length ) {
57
49
if ( playSound ) {
58
50
self . playSound ( ) ;
59
51
}
60
52
if ( showNotifications ) {
61
- this . showNotification ( countNew , response , latestNotification ) ;
53
+ this . showNotification ( newNotifications . length , response , {
54
+ full_name : newNotifications [ 0 ] . repository . full_name ,
55
+ subject : newNotifications [ 0 ] . subject . title
56
+ } ) ;
62
57
}
63
58
}
64
59
65
60
// Now Reset the previousNotifications array.
66
- self . _previousNotifications = [ ] ;
67
- _ . map ( response , function ( obj ) {
68
- self . _previousNotifications . push ( obj . id ) ;
61
+ self . _previousNotifications = _ . map ( response , function ( obj ) {
62
+ return obj . id ;
69
63
} ) ;
70
64
}
71
65
0 commit comments