diff --git a/meshuser.js b/meshuser.js index 80efe729..0eb9817d 100644 --- a/meshuser.js +++ b/meshuser.js @@ -5404,6 +5404,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use 'getnetworkinfo': serverCommandGetNetworkInfo, 'getsysinfo': serverCommandGetSysInfo, 'lastconnect': serverCommandLastConnect, + 'lastseen': serverCommandLastSeen, 'meshes': serverCommandMeshes, 'serverconsole': serverCommandServerConsole, 'servererrors': serverCommandServerErrors, @@ -5537,6 +5538,32 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use }); } + function serverCommandLastSeen(command) { + var links = parent.GetAllMeshIdWithRights(user); + var extraids = getUserExtraIds(); + db.GetAllTypeNoTypeFieldMeshFiltered(links, extraids, domain.id, 'node', null, (err, docs) => { + if (docs == null) { docs = []; } + + // use associative array to join lastconnects on to users's nodes (left join) + var LCs = {} + for (var i in docs) { + LCs[docs[i]._id] = ''; + } + + db.GetAllType('lastconnect', (err, docs) => { + for (var j in docs) { + var nodeid = docs[j]._id.substring(2); + if (LCs[nodeid] != null) { + delete docs[j]._id; + LCs[nodeid] = docs[j]; + } + } + + console.log(LCs); + }); + }); + } + function serverCommandMeshes(command) { // Request a list of all meshes this user as rights to try { ws.send(JSON.stringify({ action: 'meshes', meshes: parent.GetAllMeshWithRights(user).map(parent.CloneSafeMesh), tag: command.tag })); } catch (ex) { }