Skip to content
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

Silence failures to trigger notifications when not available #732

Merged
merged 2 commits into from Nov 16, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 23 additions & 14 deletions client/js/lounge.js
Expand Up @@ -1011,7 +1011,11 @@ $(function() {
if (msg.highlight || (options.notifyAllMessages && msg.type === "message")) {
if (!document.hasFocus() || !$(target).hasClass("active")) {
if (options.notification) {
pop.play();
try {
pop.play();
} catch (exception) {
// On mobile, sounds can not be played without user interaction.
}
}
toggleNotificationMarkers(true);

Expand All @@ -1031,19 +1035,24 @@ $(function() {
body = msg.text.replace(/\x02|\x1D|\x1F|\x16|\x0F|\x03(?:[0-9]{1,2}(?:,[0-9]{1,2})?)?/g, "").trim();
}

var notify = new Notification(title, {
body: body,
icon: "img/logo-64.png",
tag: target
});
notify.onclick = function() {
window.focus();
button.click();
this.close();
};
window.setTimeout(function() {
notify.close();
}, 5 * 1000);
try {
var notify = new Notification(title, {
body: body,
icon: "img/logo-64.png",
tag: target
});
notify.onclick = function() {
window.focus();
button.click();
this.close();
};
window.setTimeout(function() {
notify.close();
}, 5 * 1000);
} catch (exception) {
// `new Notification(...)` is not supported and should be silenced.
}

}
}
}
Expand Down