Chat error when notifications are blocked
When the user block notification for Noosfero the chat show the following behavior:
- The user receives the first message without problems.
- The second message throws an js error.
- The user does not receive anymore message until page reload.
Here is the error that is thrown:
function C.on_private_message() - error - TypeError: i is null
Stack trace:
notifyMe@http://ola.coop.br/assets/application-a9f970d6dc929458260eb2a17c407813.js:1:16260
w@http://ola.coop.br/assets/chat-d1694930e8b262c1d739411f02e4e995.js:1:4425
C.on_private_message@http://ola.coop.br/assets/chat-d1694930e8b262c1d739411f02e4e995.js:1:13797
r.Handler.prototype.run@http://ola.coop.br/assets/vendor/strophejs-1.1.3/strophe.min-f6ef4617019540346b7891378afb6eca.js:1:15799
r.Connection.prototype._dataRecv/<@http://ola.coop.br/assets/vendor/strophejs-1.1.3/strophe.min-f6ef4617019540346b7891378afb6eca.js:1:22361
r.forEachChild@http://ola.coop.br/assets/vendor/strophejs-1.1.3/strophe.min-f6ef4617019540346b7891378afb6eca.js:1:8457
r.Connection.prototype._dataRecv@http://ola.coop.br/assets/vendor/strophejs-1.1.3/strophe.min-f6ef4617019540346b7891378afb6eca.js:1:22194
Strophe.Bosh.prototype._onRequestStateChange@http://ola.coop.br/assets/vendor/strophejs-1.1.3/strophe.min-f6ef4617019540346b7891378afb6eca.js:2:5883
i is null
After some investigation, I could narrow the problem to this point in the code:
# public/javascripts/application.js
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
// Whatever the user answers, we make sure we store the information
if (!('permission' in Notification)) {
Notification.permission = permission;
}
// If the user is okay, let's create a notification
if (permission === "granted") {
notification = new Notification(title, options);
}
});
}
notification.onclick = function(){
notification.close();
// Chromium tweak
window.open().close();
window.focus();
};
Apparently, the notification is not created since the permission is blocked but the method notification.onclick
is called without any check.
Edited by Rodrigo Souto