Index: openacs-4/packages/chat/chat.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/chat/chat.info,v diff -u -r1.22.2.12 -r1.22.2.13 --- openacs-4/packages/chat/chat.info 25 Mar 2020 13:12:37 -0000 1.22.2.12 +++ openacs-4/packages/chat/chat.info 2 Apr 2020 18:09:49 -0000 1.22.2.13 @@ -9,7 +9,7 @@ f t - + Peter Alberer Server based chat with an html and ajax client. 2019-03-01 @@ -22,7 +22,7 @@ 0 - + Index: openacs-4/packages/chat/catalog/chat.en_US.ISO-8859-1.xml =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/chat/catalog/chat.en_US.ISO-8859-1.xml,v diff -u -r1.9.2.4 -r1.9.2.5 --- openacs-4/packages/chat/catalog/chat.en_US.ISO-8859-1.xml 9 Aug 2019 21:21:15 -0000 1.9.2.4 +++ openacs-4/packages/chat/catalog/chat.en_US.ISO-8859-1.xml 2 Apr 2020 18:09:49 -0000 1.9.2.5 @@ -58,6 +58,7 @@ Edit Edit Room Edit transcript + Enable notifications Enter chat room using the HTML client Enter chat room exit chat room Index: openacs-4/packages/chat/catalog/chat.es_ES.ISO-8859-1.xml =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/chat/catalog/chat.es_ES.ISO-8859-1.xml,v diff -u -r1.8.2.2 -r1.8.2.3 --- openacs-4/packages/chat/catalog/chat.es_ES.ISO-8859-1.xml 19 Feb 2020 16:59:04 -0000 1.8.2.2 +++ openacs-4/packages/chat/catalog/chat.es_ES.ISO-8859-1.xml 2 Apr 2020 18:09:49 -0000 1.8.2.3 @@ -58,6 +58,7 @@ Editar Editar sala Editar transcripci�n + Activar notificaciones Entrar con el cliente HTML Entrar en el chat Salir de la sala Index: openacs-4/packages/chat/www/chat.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/chat/www/chat.adp,v diff -u -r1.2.2.2 -r1.2.2.3 --- openacs-4/packages/chat/www/chat.adp 25 Mar 2020 13:12:37 -0000 1.2.2.2 +++ openacs-4/packages/chat/www/chat.adp 2 Apr 2020 18:09:49 -0000 1.2.2.3 @@ -7,6 +7,7 @@

#chat.active_users#:

+

#chat.Log_off# #chat.Transcript# Index: openacs-4/packages/xowiki/www/resources/chat-common.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/www/resources/Attic/chat-common.js,v diff -u -r1.10.2.6 -r1.10.2.7 --- openacs-4/packages/xowiki/www/resources/chat-common.js 2 Apr 2020 13:12:54 -0000 1.10.2.6 +++ openacs-4/packages/xowiki/www/resources/chat-common.js 2 Apr 2020 18:09:49 -0000 1.10.2.7 @@ -15,6 +15,53 @@ notifications = 0; } +// Add "Web notifications" of new messages +// https://www.w3.org/TR/notifications/ +function checkNotificationPromise() { + try { + Notification.requestPermission().then(); + } catch(e) { + return false; + } + return true; +} +function askNotificationPermission() { + var notificationBtn = document.getElementById('enableNotifications'); + // function to actually ask the permissions + function handlePermission(permission) { + // Whatever the user answers, we make sure Chrome stores the information + if(!('permission' in Notification)) { + Notification.permission = permission; + } + + // set the button to shown or hidden, depending on what the user answers + if(Notification.permission === 'denied' || Notification.permission === 'default') { + notificationBtn.style.display = 'block'; + } else { + notificationBtn.style.display = 'none'; + } + } + + // Let's check if the browser supports notifications + if (!('Notification' in window)) { + console.log("This browser does not support notifications."); + } else { + if(checkNotificationPromise()) { + Notification.requestPermission() + .then((permission) => { + handlePermission(permission); + }) + } else { + Notification.requestPermission(function(permission) { + handlePermission(permission); + }); + } + } +} +window.onload = function () { + document.getElementById('enableNotifications').addEventListener("click", askNotificationPermission); +} + // Retrieve user_id function chatGetMyUserId() { var my_user = document.getElementById('xowiki-my-user-id'); @@ -51,13 +98,21 @@ // Render the data, being a user or a message function renderData(json) { + var notificationBtn = document.getElementById('enableNotifications'); +notificationBtn.addEventListener("click", askNotificationPermission); + if (json.type == "message") { renderMessage(json); // Produce tab notification if (windowInactive) { notifications++; var newTitle = '(' + notifications + ') ' + title; document.title = newTitle; + // Web notification + var user_id = json.user_id; + var text = json.user.replace(/\\'/g, "\"") + ": " + json.message; + var img = "/shared/portrait-bits.tcl?user_id=" + user_id; + var notification = new Notification(title, { body: text, icon: img }); } } else if (json.type == "users") { renderUsers(json);