From fbde2a87a5379ede650a73527e5246dad63bd5ee Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Tue, 1 Nov 2022 23:48:21 -0700 Subject: [PATCH] Added device help request messaging notification support. --- meshcentral.js | 16 +++++++++------- meshmessaging.js | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/meshcentral.js b/meshcentral.js index bce1e2e7..ac491f38 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -2322,7 +2322,7 @@ function CreateMeshCentralServer(config, args) { // Check if any user needs email notification for (var i in users) { const user = obj.webserver.users[users[i]]; - if ((user != null) && (user.email != null) && (user.emailVerified == true)) { + if (user != null) { var notify = 0; // Device group notifications @@ -2336,7 +2336,7 @@ function CreateMeshCentralServer(config, args) { } // Email notifications - if ((mailserver != null) && ((notify & 48) != 0)) { + if ((user.email != null) && (user.emailVerified == true) && (mailserver != null) && ((notify & 48) != 0)) { if (stateSet == true) { if ((notify & 16) != 0) { mailserver.notifyDeviceConnect(user, meshid, nodeid, connectTime, connectType, powerState, serverid, extraInfo); @@ -2384,7 +2384,7 @@ function CreateMeshCentralServer(config, args) { const domainId = meshSplit[1]; if (obj.config.domains[domainId] == null) return; const mailserver = obj.config.domains[domainId].mailserver; - if (mailserver == null) return; + if ((mailserver == null) && (obj.msgserver == null)) return; // Get the device group for this device const mesh = obj.webserver.meshes[meshid]; @@ -2404,7 +2404,7 @@ function CreateMeshCentralServer(config, args) { // Check if any user needs email notification for (var i in users) { const user = obj.webserver.users[users[i]]; - if ((user != null) && (user.email != null) && (user.emailVerified == true)) { + if (user != null) { var notify = 0; // Device group notifications @@ -2417,9 +2417,11 @@ function CreateMeshCentralServer(config, args) { if (user.notify[nodeid] != null) { notify |= user.notify[nodeid]; } } - if ((notify & 64) != 0) { - mailserver.sendDeviceHelpMail(domain, user.name, user.email, devicename, nodeid, helpusername, helprequest, user.llang); - } + // Mail help request + if ((user.email != null) && (user.emailVerified == true) && ((notify & 64) != 0)) { mailserver.sendDeviceHelpMail(domain, user.name, user.email, devicename, nodeid, helpusername, helprequest, user.llang); } + + // Message help request + if ((user.msghandle != null) && ((notify & 512) != 0)) { obj.msgserver.sendDeviceHelpRequest(domain, user.name, user.msghandle, devicename, nodeid, helpusername, helprequest, user.llang); } } } } diff --git a/meshmessaging.js b/meshmessaging.js index 0b997bc0..b9449447 100644 --- a/meshmessaging.js +++ b/meshmessaging.js @@ -442,6 +442,7 @@ module.exports.CreateServer = function (parent) { if (to == null) return; parent.debug('email', "Sending device state change message to " + to); + // Format the message var sms = []; if (connections.length > 0) { sms.push('Connections: ' + connections.join(', ')); } // TODO: Translate 'Connections: ' if (disconnections.length > 0) { sms.push('Disconnections: ' + disconnections.join(', ')); } // TODO: Translate 'Disconnections: ' @@ -453,6 +454,19 @@ module.exports.CreateServer = function (parent) { obj.sendMessage(to, sms, domain, null); }; + // Send help request notification + obj.sendDeviceHelpRequest = function (domain, username, to, devicename, nodeid, helpusername, helprequest, lang) { + if (to == null) return; + parent.debug('email', "Sending device help request message to " + to); + + // Format the message + var sms = "Help Request from " + devicename + ': ' + helprequest; // TODO: Translate 'Help Request from {0}:' + if (sms.length > 1000) { sms = sms.substring(0, 997) + '...'; } // Limit messages to 1000 characters + + // Send the message + obj.sendMessage(to, sms, domain, null); + } + // // Device connetion and disconnection notifications