Added user notification timeout support.
Ylian Saint-Hilaire committed
Jul 31, 2020 at 15:08 UTC
8e67568949132d17fc96fbe1036e56c19dae18a9
3 files changed
+51
-9
meshuser.js
+2
@@ -1612,6 +1612,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1612
1613
// Create the notification message
1614
var notification = { action: 'msg', type: 'notify', domain: domain.id, value: command.msg, title: user.name, icon: 0, tag: 'broadcast', id: Math.random() };
1615
+ if ((typeof command.maxtime == 'number') && (command.maxtime > 0)) { notification.maxtime = command.maxtime; }
1616
1617
// Send the notification on all user sessions for this server
1618
for (var i in parent.wssessions2) {
@@ -2460,6 +2461,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
2461
2462
// Create the notification message
2463
var notification = { action: 'msg', type: 'notify', id: Math.random(), value: command.msg, title: user.name, icon: 8, userid: user._id, username: user.name };
2464
+ if ((typeof command.maxtime == 'number') && (command.maxtime > 0)) { notification.maxtime = command.maxtime; }
2465
2466
// Get the list of sessions for this user
2467
var sessions = parent.wssessions[command.userid];
package.json
+18
-1
@@ -34,6 +34,8 @@
34
"sample-config-advanced.json"
35
],
36
"dependencies": {
37
+ "archiver": "^4.0.2",
38
+ "archiver-zip-encrypted": "^1.0.8",
39
"body-parser": "^1.19.0",
40
"cbor": "^4.1.5",
41
"compression": "^1.7.4",
@@ -42,14 +44,29 @@
44
"express": "^4.17.0",
45
"express-handlebars": "^3.1.0",
46
"express-ws": "^4.0.0",
47
+ "image-size": "^0.8.3",
48
"ipcheck": "^0.1.0",
49
+ "jwt-simple": "^0.5.6",
50
"minimist": "^1.2.0",
51
+ "mongodb": "^3.6.0",
52
"multiparty": "^4.2.1",
53
"nedb": "^1.8.0",
54
"node-forge": "^0.8.4",
55
+ "node-rdpjs-2": "^0.3.5",
56
+ "node-windows": "^0.1.14",
57
+ "otplib": "^10.2.3",
58
+ "passport": "^0.4.1",
59
+ "passport-azure-oauth2": "^0.1.0",
60
+ "passport-github2": "^0.1.12",
61
+ "passport-google-oauth20": "^2.0.0",
62
+ "passport-reddit": "^0.2.4",
63
+ "passport-twitter": "^1.0.4",
64
+ "plivo": "^4.7.0",
65
+ "saslprep": "^1.0.3",
66
"ws": "^6.2.1",
67
"xmldom": "^0.1.27",
52
- "yauzl": "^2.10.0"
68
+ "yauzl": "^2.10.0",
69
+ "yubikeyotp": "^0.2.0"
70
},
71
"devDependencies": {},
72
"repository": {
views/default.handlebars
+31
-8
@@ -2105,6 +2105,7 @@
2105
if (message.nodeid != null) { n.nodeid = message.nodeid; }
2106
if (message.tag != null) { n.tag = message.tag; }
2107
if (message.username != null) { n.username = message.username; }
2108
+ if (typeof message.maxtime == 'number') { n.maxtime = message.maxtime; }
2109
addNotification(n);
2110
} else if (message.type == 'ps') {
2111
showDeskToolsProcesses(message);
@@ -2140,6 +2141,7 @@
2141
if (message.id != null) { n.id = message.id; }
2142
if (message.tag != null) { n.tag = message.tag; }
2143
if (message.username != null) { n.username = message.username; }
2144
+ if (typeof message.maxtime == 'number') { n.maxtime = message.maxtime; }
2145
addNotification(n);
2146
}
2147
}
@@ -2878,6 +2880,7 @@
2880
var n = { text: message.event.value, title: message.event.title, icon: message.event.icon };
2881
if (message.id != null) { n.id = message.id; }
2882
if (message.event.tag != null) { n.tag = message.event.tag; }
2883
+ if (typeof message.maxtime == 'number') { n.maxtime = message.maxtime; }
2884
addNotification(n);
2885
break;
2886
}
@@ -5841,7 +5844,9 @@
5844
5845
function showNotes(readonly, noteid) {
5846
if (xxdialogMode) return;
5844
- setDialogMode(2, "Notes", 2, showNotesEx, '<textarea id=d2devNotes ro=' + readonly + ' noteid=' + noteid + ' readonly style=background-color:#fcf3cf;width:100%;height:200px;resize:none;overflow-y:scroll></textarea><span style=font-size:10px>' + "Device group notes can be viewed and changed by other device group administrators." + '<span>', noteid);
5847
+ var x = '<textarea id=d2devNotes ro=' + readonly + ' noteid=' + noteid + ' readonly style=background-color:#fcf3cf;width:100%;height:200px;resize:none;overflow-y:scroll></textarea>';
5848
+ if (noteid.startsWith('node%2F%2F')) { x += '<span style=font-size:10px>' + "Device group notes can be viewed and changed by other device group administrators." + '<span>'; }
5849
+ setDialogMode(2, "Notes", 2, showNotesEx, x, noteid);
5850
meshserver.send({ action: 'getNotes', id: decodeURIComponent(noteid) });
5851
}
5852
@@ -10794,12 +10799,21 @@
10799
function showUserAlertDialog(e, userid) {
10800
if (xxdialogMode) return;
10801
haltEvent(e);
10797
- setDialogMode(2, format("Notify {0}", EscapeHtml(users[decodeURIComponent(userid)].name)), 3, showUserAlertDialogEx, "Send a text notification to this user." + '<textarea id=d2notifyText maxlength=2048 style="width:100%;height:184px;resize:none"></textarea>', userid);
10802
+ var x = '<div style=margin-bottom:6px>' + "Send a text notification to this user." + '</div><textarea id=d2notifyText maxlength=2048 style="width:100%;height:184px;resize:none;background-color:#fcf3cf"></textarea>';
10803
+ x += '<select style=width:100% id=broadcastMessageMaxTime>';
10804
+ x += '<option value=0>' + "Show message until dismissed by user" + '</option>';
10805
+ x += '<option value=10>' + "Show for 10 seconds" + '</option>';
10806
+ x += '<option value=60>' + "Show for 1 minute" + '</option>';
10807
+ x += '<option value=300>' + "Show for 5 minutes" + '</option>';
10808
+ x += '</select>';
10809
+ setDialogMode(2, format("Notify {0}", EscapeHtml(users[decodeURIComponent(userid)].name)), 3, showUserAlertDialogEx, x, userid);
10810
Q('d2notifyText').focus();
10811
return false;
10812
}
10813
10802
- function showUserAlertDialogEx(button, userid) { meshserver.send({ action: 'notifyuser', userid: decodeURIComponent(userid), msg: Q('d2notifyText').value }); }
10814
+ function showUserAlertDialogEx(button, userid) {
10815
+ meshserver.send({ action: 'notifyuser', userid: decodeURIComponent(userid), msg: Q('d2notifyText').value, maxtime: parseInt(Q('broadcastMessageMaxTime').value) });
10816
+ }
10817
10818
function p4batchAccountCreate() {
10819
if (xxdialogMode) return;
@@ -10864,13 +10878,19 @@
10878
10879
function showUserBroadcastDialog(targetid) {
10880
if (xxdialogMode) return;
10867
- var x = "Broadcast a message to all connected users." + '<textarea id=broadcastMessage value="" maxlength="256"/></textarea>';
10881
+ var x = '<div style=margin-bottom:6px>' + "Broadcast a message to all connected users." + '</div><textarea id=broadcastMessage style="width:100%;height:184px;resize:none;background-color:#fcf3cf" value="" maxlength=2048 /></textarea>';
10882
+ x += '<select style=width:100% id=broadcastMessageMaxTime>';
10883
+ x += '<option value=0>' + "Show message until dismissed by user" + '</option>';
10884
+ x += '<option value=10>' + "Show for 10 seconds" + '</option>';
10885
+ x += '<option value=60>' + "Show for 1 minute" + '</option>';
10886
+ x += '<option value=300>' + "Show for 5 minutes" + '</option>';
10887
+ x += '</select>';
10888
setDialogMode(2, "Broadcast Message", 3, showUserBroadcastDialogEx, x, targetid?decodeURIComponent(targetid):null);
10889
Q('broadcastMessage').focus();
10890
}
10891
10892
function showUserBroadcastDialogEx(b, targetid) {
10873
- meshserver.send({ action: 'userbroadcast', msg: Q('broadcastMessage').value, target: targetid });
10893
+ meshserver.send({ action: 'userbroadcast', msg: Q('broadcastMessage').value, target: targetid, maxtime: parseInt(Q('broadcastMessageMaxTime').value) });
10894
}
10895
10896
function showCreateNewAccountDialog() {
@@ -11621,10 +11641,10 @@
11641
x += '</table></div><br />';
11642
11643
// Add action buttons
11624
- x += '<input type=button value="' + "Notes" + '" title="' + "View notes about this user" + '" onclick=showNotes(false,"' + userid + '") />';
11625
- if (user.phone && (features & 0x02000000)) { x += '<input type=button value="' + "SMS" + '" title="' + "Send a SMS message to this user" + '" onclick=showSendSMS("' + userid + '") />'; }
11644
+ x += '<input type=button value="' + "Notes" + '" title="' + "View notes about this user" + '" onclick=showNotes(false,"' + encodeURIComponentEx(userid) + '") />';
11645
+ if (user.phone && (features & 0x02000000)) { x += '<input type=button value="' + "SMS" + '" title="' + "Send a SMS message to this user" + '" onclick=showSendSMS("' + encodeURIComponentEx(userid) + '") />'; }
11646
if ((typeof user.email == 'string') && (user.emailVerified === true) && (features & 0x00000040)) { x += '<input type=button value="' + "Email" + '" title="' + "Send a email message to this user" + '" onclick=showSendEmail("' + userid + '") />'; }
11627
- if (!self && (activeSessions > 0)) { x += '<input type=button value="' + "Notify" + '" title="' + "Send user notification" + '" onclick=showUserAlertDialog(event,"' + userid + '") />'; }
11647
+ if (!self && (activeSessions > 0)) { x += '<input type=button value="' + "Notify" + '" title="' + "Send user notification" + '" onclick=showUserAlertDialog(event,"' + encodeURIComponentEx(userid) + '") />'; }
11648
11649
// Setup the panel
11650
QH('p30html', x);
@@ -12319,6 +12339,9 @@
12339
notification.onclick = function (e) { notificationSelected(e.target.id, true); }
12340
n.notification = notification;
12341
}
12342
+
12343
+ // If the notification has a max time, setup the timer here.
12344
+ if ((typeof n.maxtime == 'number') && (n.maxtime > 0)) { var trigger = function notifyRemoveTrigger() { notificationDelete(notifyRemoveTrigger.xid); }; trigger.xid = n.id; setTimeout(trigger, n.maxtime * 1000); }
12345
}
12346
12347
// Remove all notifications