Added device help request messaging notification support.
Ylian Saint-Hilaire committed
Nov 1, 2022 at 23:48 UTC
fbde2a87a5379ede650a73527e5246dad63bd5ee
2 files changed
+23
-7
meshcentral.js
+9
-7
@@ -2322,7 +2322,7 @@ function CreateMeshCentralServer(config, args) {
2322
// Check if any user needs email notification
2323
for (var i in users) {
2324
const user = obj.webserver.users[users[i]];
2325
- if ((user != null) && (user.email != null) && (user.emailVerified == true)) {
2325
+ if (user != null) {
2326
var notify = 0;
2327
2328
// Device group notifications
@@ -2336,7 +2336,7 @@ function CreateMeshCentralServer(config, args) {
2336
}
2337
2338
// Email notifications
2339
- if ((mailserver != null) && ((notify & 48) != 0)) {
2339
+ if ((user.email != null) && (user.emailVerified == true) && (mailserver != null) && ((notify & 48) != 0)) {
2340
if (stateSet == true) {
2341
if ((notify & 16) != 0) {
2342
mailserver.notifyDeviceConnect(user, meshid, nodeid, connectTime, connectType, powerState, serverid, extraInfo);
@@ -2384,7 +2384,7 @@ function CreateMeshCentralServer(config, args) {
2384
const domainId = meshSplit[1];
2385
if (obj.config.domains[domainId] == null) return;
2386
const mailserver = obj.config.domains[domainId].mailserver;
2387
- if (mailserver == null) return;
2387
+ if ((mailserver == null) && (obj.msgserver == null)) return;
2388
2389
// Get the device group for this device
2390
const mesh = obj.webserver.meshes[meshid];
@@ -2404,7 +2404,7 @@ function CreateMeshCentralServer(config, args) {
2404
// Check if any user needs email notification
2405
for (var i in users) {
2406
const user = obj.webserver.users[users[i]];
2407
- if ((user != null) && (user.email != null) && (user.emailVerified == true)) {
2407
+ if (user != null) {
2408
var notify = 0;
2409
2410
// Device group notifications
@@ -2417,9 +2417,11 @@ function CreateMeshCentralServer(config, args) {
2417
if (user.notify[nodeid] != null) { notify |= user.notify[nodeid]; }
2418
}
2419
2420
- if ((notify & 64) != 0) {
2421
- mailserver.sendDeviceHelpMail(domain, user.name, user.email, devicename, nodeid, helpusername, helprequest, user.llang);
2422
- }
2420
+ // Mail help request
2421
+ if ((user.email != null) && (user.emailVerified == true) && ((notify & 64) != 0)) { mailserver.sendDeviceHelpMail(domain, user.name, user.email, devicename, nodeid, helpusername, helprequest, user.llang); }
2422
+
2423
+ // Message help request
2424
+ if ((user.msghandle != null) && ((notify & 512) != 0)) { obj.msgserver.sendDeviceHelpRequest(domain, user.name, user.msghandle, devicename, nodeid, helpusername, helprequest, user.llang); }
2425
}
2426
}
2427
}
meshmessaging.js
+14
@@ -442,6 +442,7 @@ module.exports.CreateServer = function (parent) {
442
if (to == null) return;
443
parent.debug('email', "Sending device state change message to " + to);
444
445
+ // Format the message
446
var sms = [];
447
if (connections.length > 0) { sms.push('Connections: ' + connections.join(', ')); } // TODO: Translate 'Connections: '
448
if (disconnections.length > 0) { sms.push('Disconnections: ' + disconnections.join(', ')); } // TODO: Translate 'Disconnections: '
@@ -453,6 +454,19 @@ module.exports.CreateServer = function (parent) {
454
obj.sendMessage(to, sms, domain, null);
455
};
456
457
+ // Send help request notification
458
+ obj.sendDeviceHelpRequest = function (domain, username, to, devicename, nodeid, helpusername, helprequest, lang) {
459
+ if (to == null) return;
460
+ parent.debug('email', "Sending device help request message to " + to);
461
+
462
+ // Format the message
463
+ var sms = "Help Request from " + devicename + ': ' + helprequest; // TODO: Translate 'Help Request from {0}:'
464
+ if (sms.length > 1000) { sms = sms.substring(0, 997) + '...'; } // Limit messages to 1000 characters
465
+
466
+ // Send the message
467
+ obj.sendMessage(to, sms, domain, null);
468
+ }
469
+
470
471
//
472
// Device connetion and disconnection notifications