From 9af8c783507bf76ae6b66d570ed7fa8953d4f8fd Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Mon, 29 Apr 2019 18:48:51 -0700 Subject: [PATCH] Improved web notifications --- meshuser.js | 2 +- package.json | 2 +- views/default-min.handlebars | 2 +- views/default.handlebars | 44 +++++++++++++++++++--------------- views/login-min.handlebars | 2 +- views/messenger-min.handlebars | 2 +- 6 files changed, 30 insertions(+), 24 deletions(-) diff --git a/meshuser.js b/meshuser.js index 76dc2efd..cfa6f01c 100644 --- a/meshuser.js +++ b/meshuser.js @@ -1112,7 +1112,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use if ((user.groups != null) && (user.groups.length > 0) && ((chguser.groups == null) || (findOne(chguser.groups, user.groups) == false))) break; // Create the notification message - var notification = { "action": "msg", "type": "notify", "value": command.msg, "title": user.name, "icon": 9, "userid": user._id, "username": user.name }; + var notification = { action: "msg", type: "notify", value: command.msg, title: user.name, icon: 8, userid: user._id, username: user.name }; // Get the list of sessions for this user var sessions = parent.wssessions[command.userid]; diff --git a/package.json b/package.json index 33d256e7..1bad58e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.3.3-i", + "version": "0.3.3-j", "keywords": [ "Remote Management", "Intel AMT", diff --git a/views/default-min.handlebars b/views/default-min.handlebars index d52a4c81..f181e863 100644 --- a/views/default-min.handlebars +++ b/views/default-min.handlebars @@ -1 +1 @@ - {{{title}}}
{{{title}}}
{{{title2}}}

{{{logoutControl}}}

 

\ No newline at end of file + {{{title}}}
{{{title}}}
{{{title2}}}

{{{logoutControl}}}

 

\ No newline at end of file diff --git a/views/default.handlebars b/views/default.handlebars index 549b9755..b7ce816b 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -3831,6 +3831,7 @@ if (terminalAccess) { setupTerminal(); } if (fileAccess) { setupFiles(); } var consoleRights = ((meshrights & 16) != 0); + console.log('consoleRights', consoleRights); if (consoleRights) { setupConsole(); } else { if (panel == 15) { panel = 10; } } // Show or hide the tabs @@ -7332,16 +7333,12 @@ } else { for (var i in notifications) { var n = notifications[i]; - var t = ''; + var t = '' + n.title + ': ' var d = new Date(n.time); var icon = 0; if (n.nodeid != null) { var node = getNodeFromId(n.nodeid); - if (node != null) { - //console.log(node); - icon = node.icon; - t = '' + node.name + ': ' - } + if (node != null) { icon = node.icon; t = '' + node.name + ': ' } } r += '
X
' + t + n.text + '
'; @@ -7353,10 +7350,16 @@ } // A notification was selected - function notificationSelected(id) { + function notificationSelected(id, del) { var j = -1; for (var i in notifications) { if (notifications[i].id == id) { j = i; } } - if (j != -1) { notificationSelectedEx(notifications[j], id); } + if (j != -1) { + notificationSelectedEx(notifications[j], id); + if (del && notifications[j]) { + if (notifications[j].notification) { notifications[j].notification.close(); delete notifications[j].notification; } + notificationDelete(id); + } + } } function notificationSelectedEx(n, id) { @@ -7368,7 +7371,7 @@ else if (n.tag == 'console') gotoDevice(n.nodeid, 15); // Files else gotoDevice(n.nodeid, 10); // General } else { - if (n.tag.startsWith('meshmessenger/')) { + if ((n.tag != null) && n.tag.startsWith('meshmessenger/')) { window.open('/messenger?id=' + n.tag + '&title=' + encodeURIComponent(n.username), n.tag.split('/')[2]); notificationDelete(id); } @@ -7381,6 +7384,7 @@ if (e != null) { for (var i in notifications) { if (notifications[i].id == id) { j = i; } } if (j != -1) { + if (notifications[j].notification) { notifications[j].notification.close(); delete notifications[j].notification; } notifications.splice(j, 1); e.parentNode.removeChild(e); setNotificationCount(notifications.length); @@ -7396,9 +7400,17 @@ // Add a new notification and play the notification sound function addNotification(n) { + // Show notification within the web page. + if (n.time == null) { n.time = Date.now(); } + if (n.id == null) { n.id = Math.random(); } + notifications.unshift(n); + setNotificationCount(notifications.length); + clickNotificationIcon(true); + Q('chimes').play(); + // If web notifications are granted, use it. + var notification = null; if (Notification && (Notification.permission == "granted")) { - var notification; if (n.nodeid) { var node = getNodeFromId(n.nodeid); if (node) { notification = new Notification("{{{title}}} - " + node.name, { tag: n.tag, body: n.text, icon: '/images/notify/icons128-' + node.icon + '.png' }); } @@ -7406,18 +7418,12 @@ if (n.icon == null) { n.icon = 0; } notification = new Notification("{{{title}}} - " + n.title, { tag: n.tag, body: n.text, icon: '/images/notify/icons128-' + n.icon + '.png' }); } + notification.id = n.id; notification.xtag = n.tag; notification.nodeid = n.nodeid; notification.username = n.username; - notification.onclick = function (e) { notificationSelectedEx(e.target); } - Q('chimes').play(); - } else { - if (n.time == null) { n.time = Date.now(); } - if (n.id == null) { n.id = Math.random(); } - notifications.unshift(n); - setNotificationCount(notifications.length); - Q('chimes').play(); - clickNotificationIcon(true); + notification.onclick = function (e) { notificationSelected(e.target.id, true); } + n.notification = notification; } } diff --git a/views/login-min.handlebars b/views/login-min.handlebars index 3517645e..ac2ab582 100644 --- a/views/login-min.handlebars +++ b/views/login-min.handlebars @@ -1 +1 @@ - {{{title}}} - Login
{{{title}}}
{{{title2}}}

Welcome


\ No newline at end of file + {{{title}}} - Login
{{{title}}}
{{{title2}}}

Welcome


\ No newline at end of file diff --git a/views/messenger-min.handlebars b/views/messenger-min.handlebars index 29b59005..31e96d59 100644 --- a/views/messenger-min.handlebars +++ b/views/messenger-min.handlebars @@ -1 +1 @@ - MeshMessenger
MeshMessenger
\ No newline at end of file + MeshMessenger
MeshMessenger
\ No newline at end of file