Merge pull request #127 from thelounge/astorije/notification-invites

Add notifications for channel invites
This commit is contained in:
Pavel Djundik 2016-02-29 11:26:20 +02:00
commit 3b17b00072

View File

@ -682,21 +682,31 @@ $(function() {
chat.on("msg", ".messages", function(e, target, msg) { chat.on("msg", ".messages", function(e, target, msg) {
var button = sidebar.find(".chan[data-target='" + target + "']"); var button = sidebar.find(".chan[data-target='" + target + "']");
var isQuery = button.hasClass("query"); var isQuery = button.hasClass("query");
if (msg.highlight || isQuery || (options.notifyAllMessages && msg.type === "message")) { if (msg.type === "invite" || msg.highlight || isQuery || (options.notifyAllMessages && msg.type === "message")) {
if (!document.hasFocus() || !$(target).hasClass("active")) { if (!document.hasFocus() || !$(target).hasClass("active")) {
if (options.notification) { if (options.notification) {
pop.play(); pop.play();
} }
toggleFaviconNotification(true); toggleFaviconNotification(true);
if (options.badge && Notification.permission === "granted") { if (options.badge && Notification.permission === "granted") {
var title = msg.from; var title;
var body;
if (msg.type === "invite") {
title = "New channel invite:";
body = msg.from + " invited you to " + msg.text;
} else {
title = msg.from;
if (!isQuery) { if (!isQuery) {
title += " (" + button.text().trim() + ")"; title += " (" + button.text().trim() + ")";
} }
title += " says:"; title += " says:";
body = msg.text.trim();
}
var notify = new Notification(title, { var notify = new Notification(title, {
body: msg.text.trim(), body: body,
icon: "img/logo-64.png", icon: "img/logo-64.png",
tag: target tag: target
}); });