Skip to content

Commit adabd09

Browse files
author
Emmanouil Konstantinidis
committed
Jake's comments
1 parent c2b47ce commit adabd09

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

src/js/stores/sound-notification.js

+11-17
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ var SoundNotificationStore = Reflux.createStore({
1010

1111
init: function () {
1212
this._previousNotifications = [];
13+
this._audio = new Audio('sounds/digi.wav');
1314
},
1415

1516
playSound: function () {
16-
var audio = new Audio('sounds/digi.wav');
17-
audio.play();
17+
this._audio.play();
1818
},
1919

2020
showNotification: function (countNew, response, latestNotification) {
@@ -40,32 +40,26 @@ var SoundNotificationStore = Reflux.createStore({
4040
if (!playSound && !showNotifications) { return; }
4141

4242
// 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);
5345
});
5446

5547
// Play Sound / Show Notification.
56-
if (countNew > 0) {
48+
if (newNotifications && newNotifications.length) {
5749
if (playSound) {
5850
self.playSound();
5951
}
6052
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+
});
6257
}
6358
}
6459

6560
// 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;
6963
});
7064
}
7165

0 commit comments

Comments
 (0)