Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #26897 from jrburke/bug1042361-email-quiet-notific…
Browse files Browse the repository at this point in the history
…ation

Bug 1042361 - [email] Avoid disruptive notification modes if a notification for the account already exists r=asuth
  • Loading branch information
jrburke committed Jan 7, 2015
2 parents 0c56746 + 3bf700b commit 7d5288b
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions apps/email/js/sync.js
Expand Up @@ -45,7 +45,8 @@ define(function(require) {
console.log('email: notifications not available');
sendNotification = function() {};
} else {
sendNotification = function(notificationId, title, body, iconUrl, data) {
sendNotification = function(notificationId, title, body,
iconUrl, data, behavior) {
console.log('Notification sent for ' + notificationId);

if (Notification.permission !== 'granted') {
Expand All @@ -58,15 +59,23 @@ define(function(require) {

//TODO: consider setting dir and lang?
//https://developer.mozilla.org/en-US/docs/Web/API/notification
var notification = new Notification(title, {
var notificationOptions = {
body: body,
icon: iconUrl,
tag: notificationId,
data: data,
mozbehavior: {
noscreen: true
}
});
};

if (behavior) {
Object.keys(behavior).forEach(function(key) {
notificationOptions.mozbehavior[key] = behavior[key];
});
}

var notification = new Notification(title, notificationOptions);

// If the app is open, but in the background, when the notification
// comes in, then we do not get notifived via our mozSetMessageHandler
Expand Down Expand Up @@ -258,7 +267,7 @@ define(function(require) {
return;
}

var dataObject, subject, body,
var dataObject, subject, body, behavior,
count = result.count,
oldFromNames = [];

Expand Down Expand Up @@ -287,6 +296,19 @@ define(function(require) {
fromNames: newFromNames
};

// If already have a notification, then do not bother with sound or
// vibration for this update. Longer term, the notification standard
// will have a "silent" option, but using a non-existent URL as
// suggested in bug 1042361 in the meantime.
if (existingData && existingData.count) {
behavior = {
soundFile: 'does-not-exist-to-simulate-silent',
// Cannot use 0 since system/js/notifications.js explicitly
// ignores [0] values. [1] is good enough for this purpose.
vibrationPattern: [1]
};
}

if (model.getAccountCount() === 1) {
subject = mozL10n.get('new-emails-notify-one-account', {
n: count
Expand Down Expand Up @@ -332,7 +354,8 @@ define(function(require) {
subject,
body,
iconUrl,
dataObject
dataObject,
behavior
);
});

Expand Down

0 comments on commit 7d5288b

Please sign in to comment.