-
Notifications
You must be signed in to change notification settings - Fork 275
Notifications / Sounds #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3fdf5aa
3447a31
35af639
25bad56
af037e5
0776ba5
2c530b2
24c973e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ var NotificationsStore = Reflux.createStore({ | |
|
||
init: function () { | ||
this._notifications = []; | ||
this._previousNotifications = []; | ||
}, | ||
|
||
updateTrayIcon: function (notifications) { | ||
|
@@ -21,6 +22,35 @@ var NotificationsStore = Reflux.createStore({ | |
} | ||
}, | ||
|
||
isNewNotification: function (response) { | ||
var self = this; | ||
var playSound = SettingsStore.getSettings().playSound; | ||
|
||
if (!playSound) { return; } | ||
|
||
// Check if notification is already in the store. | ||
var isNew = false; | ||
_.map(response, function (obj) { | ||
if (!_.contains(self._previousNotifications, obj.id)) { | ||
isNew = true; | ||
} | ||
}); | ||
|
||
// Play Sound. | ||
if (isNew) { | ||
if (playSound) { | ||
var audio = new Audio('sounds/digi.wav'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would load this when the app first loads. :) Perhaps have a store for sounds / notifications. |
||
audio.play(); | ||
} | ||
} | ||
|
||
// Now Reset the previousNotifications array. | ||
self._previousNotifications = []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. self._previousNotifications = _.map(response, function (obj) {
return obj.id;
}); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should clean the 'previousNotifications' every time it receives a new payload so that's why.. |
||
_.map(response, function (obj) { | ||
self._previousNotifications.push(obj.id); | ||
}); | ||
}, | ||
|
||
onGetNotifications: function () { | ||
var self = this; | ||
var participating = SettingsStore.getSettings().participating; | ||
|
@@ -33,6 +63,7 @@ var NotificationsStore = Reflux.createStore({ | |
// Success - Do Something. | ||
Actions.getNotifications.completed(response.body); | ||
self.updateTrayIcon(response.body); | ||
self.isNewNotification(response.body); | ||
} else { | ||
// Error - Show messages. | ||
Actions.getNotifications.failed(err); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep this function pure you should use _.some (also has alias _.any)...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed will have a further look in cleaning it up on #57 .