notifications: Check whether addEventListener is a function.

It's crazy that we need to do this; one would think that Electron apps
whose sole purpose is to be used with multiple team chat tools would
at least implement the standard desktop notification API correctly.

But it seems worth making this tactical change to prevent every
desktop notification throwing a traceback on those platforms, which if
nothing else results in a lot of error spam.

Fixes #15103.
This commit is contained in:
Tim Abbott 2020-06-18 12:47:01 -07:00
parent d32e8276d2
commit b840ec9491
1 changed files with 17 additions and 10 deletions

View File

@ -387,16 +387,23 @@ function process_notification(notification) {
msg_count: msg_count,
message_id: message.id,
});
notification_object.addEventListener("click", () => {
notification_object.close();
if (message.type !== "test-notification") {
narrow.by_topic(message.id, {trigger: 'notification'});
}
window.focus();
});
notification_object.addEventListener("close", () => {
notice_memory.delete(key);
});
if (_.isFunction(notification_object.addEventListener)) {
// Sadly, some third-party Electron apps like Franz/Ferdi
// misimplement the Notification API not inheriting from
// EventTarget. This results in addEventListener being
// unavailable for them.
notification_object.addEventListener("click", () => {
notification_object.close();
if (message.type !== "test-notification") {
narrow.by_topic(message.id, {trigger: 'notification'});
}
window.focus();
});
notification_object.addEventListener("close", () => {
notice_memory.delete(key);
});
}
} else {
in_browser_notify(message, title, content, raw_operators, opts);
}