From af0ff0914469e75f61153df3c468a893066e6f17 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Thu, 23 Jun 2022 11:43:47 -0700 Subject: [PATCH] Fixed empty notifications titles, #4155 --- meshuser.js | 7 ++++++- views/default.handlebars | 7 +++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/meshuser.js b/meshuser.js index 2c2ec115..30b27364 100644 --- a/meshuser.js +++ b/meshuser.js @@ -2913,7 +2913,6 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use // Perform input validation try { if (common.validateStrArray(command.nodeids, 1, 256) == false) { err = "Invalid nodeids"; } // Check nodeids - else if (common.validateString(command.title, 1, 512) == false) { err = "Invalid title"; } // Check title else if (common.validateString(command.msg, 1, 4096) == false) { err = "Invalid message"; } // Check message else { var nodeids = []; @@ -2928,6 +2927,12 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use break; } + // Check the title, if needed, use a default one + if (common.validateString(command.title, 1, 512) == false) { delete command.title } // Check title + if ((command.title == null) && (typeof domain.notificationmessages == 'object') && (typeof domain.notificationmessages.title == 'string')) { command.title = domain.notificationmessages.title; } + if ((command.title == null) && (typeof domain.title == 'string')) { command.title = domain.title; } + if (command.title == null) { command.title = "MeshCentral"; } + for (i in command.nodeids) { // Get the node and the rights for this node parent.GetNodeWithRights(domain, user, command.nodeids[i], function (node, rights, visible) { diff --git a/views/default.handlebars b/views/default.handlebars index 6a23166e..1a250ce7 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -5551,6 +5551,7 @@ var op = Q('d2deviceop').value, title = Q('dp2notifyTitle').value, msg = Q('d2notifyMsg').value, chkNodeIds = getCheckedDevices(); if (msg.length == 0) return; if (title == '') { title = decodeURIComponent('{{{extitle}}}'); } + if (title == '') { title = "MeshCentral"; } if (op == 1) { // MessageBox for (var i = 0; i < chkNodeIds.length; i++) { meshserver.send({ action: 'msg', type: 'messagebox', nodeid: chkNodeIds[i], title: title, msg: msg }); } } else if (op == 2) { // Toast @@ -7599,10 +7600,12 @@ } function deviceMessageFunctionEx() { + var title = decodeURIComponent('{{{extitle}}}'); + if (title == '') { title = "MeshCentral"; } if (currentNode.pmt == 1) { - meshserver.send({ action: 'pushmessage', nodeid: currentNode._id, title: decodeURIComponent('{{{extitle}}}'), msg: Q('d2devMessage').value }); + meshserver.send({ action: 'pushmessage', nodeid: currentNode._id, title: title, msg: Q('d2devMessage').value }); } else { - meshserver.send({ action: 'msg', type: 'messagebox', nodeid: currentNode._id, title: decodeURIComponent('{{{extitle}}}'), msg: Q('d2devMessage').value }); + meshserver.send({ action: 'msg', type: 'messagebox', nodeid: currentNode._id, title: title, msg: Q('d2devMessage').value }); } }