From 2bd67445dcb342bcfb3a11498a808de187afd4a5 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Fri, 15 Apr 2022 14:21:36 -0700 Subject: [PATCH] Relay device group improvements. --- meshuser.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/meshuser.js b/meshuser.js index f1a5f8ff..4e5e6622 100644 --- a/meshuser.js +++ b/meshuser.js @@ -1989,6 +1989,17 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use if (parent.parent.authlog) { parent.parent.authLog('https', 'User ' + user.name + ' created device group ' + mesh.name); } try { ws.send(JSON.stringify({ action: 'createmesh', responseid: command.responseid, result: 'ok', meshid: meshid, links: links })); } catch (ex) { } + + // If needed, event that a device is now a device group relay + if (mesh.relayid != null) { + // Get the node and the rights for this node + parent.GetNodeWithRights(domain, user, mesh.relayid, function (node, rights, visible) { + if (node == null) return; + var event = { etype: 'node', userid: user._id, username: user.name, action: 'changenode', nodeid: node._id, domain: domain.id, msg: 'Is a relay for ' + mesh.name + '.', msgid: 153, msgArgs: [mesh.name], node: parent.CloneSafeNode(node) }; + if (db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the node. Another event will come. + parent.parent.DispatchEvent(parent.CreateNodeDispatchTargets(node.meshid, node._id, [user._id]), obj, event); + }); + } }); break; } @@ -2205,6 +2216,14 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use if (db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the node. Another event will come. parent.parent.DispatchEvent(parent.CreateNodeDispatchTargets(node.meshid, node._id, [user._id]), obj, event); }); + } else if ((mesh.relayid != null) && (changesids.indexOf(1) >= 0)) { + // Notify of node name change, get the node and the rights for this node, we just want to trigger a device update. + parent.GetNodeWithRights(domain, user, mesh.relayid, function (node, rights, visible) { + if (node == null) return; + var event = { etype: 'node', userid: user._id, username: user.name, action: 'changenode', nodeid: node._id, domain: domain.id, node: parent.CloneSafeNode(node), nolog: 1 }; + if (db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the node. Another event will come. + parent.parent.DispatchEvent(parent.CreateNodeDispatchTargets(node.meshid, node._id, [user._id]), obj, event); + }); } if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'editmesh', responseid: command.responseid, result: 'ok' })); } catch (ex) { } }