Added device help request messaging notification support.

This commit is contained in:
Ylian Saint-Hilaire 2022-11-01 23:48:21 -07:00
parent 1a6e78efed
commit fbde2a87a5
2 changed files with 23 additions and 7 deletions

View File

@ -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); }
}
}
}

View File

@ -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