From 788e40c84e278c6c6f4e2a9b53f3820d78c35b00 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Wed, 19 Feb 2020 00:15:57 -0400 Subject: [PATCH 1/2] move vars --- services/gunDB/Mediator/index.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/services/gunDB/Mediator/index.js b/services/gunDB/Mediator/index.js index e25240c8..4f04a03e 100644 --- a/services/gunDB/Mediator/index.js +++ b/services/gunDB/Mediator/index.js @@ -296,6 +296,14 @@ const throwOnInvalidToken = async token => { } } +const getGun = () => { + return gun +} + +const getUser = () => { + return user +} + class Mediator { /** * @param {Readonly} socket @@ -1136,14 +1144,6 @@ const createMediator = socket => { return new Mediator(socket) } -const getGun = () => { - return gun -} - -const getUser = () => { - return user -} - module.exports = { authenticate, logoff, From 1d9215c7f6db2a93e071aed10ad4f5a4e72306b0 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Wed, 19 Feb 2020 00:21:36 -0400 Subject: [PATCH 2/2] set last seen action --- services/gunDB/Mediator/index.js | 28 ++++++++++++++++++++++++++++ utils/encryptionStore.js | 7 ++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/services/gunDB/Mediator/index.js b/services/gunDB/Mediator/index.js index 4f04a03e..561889ff 100644 --- a/services/gunDB/Mediator/index.js +++ b/services/gunDB/Mediator/index.js @@ -344,6 +344,34 @@ class Mediator { this.socket.on(Event.ON_SEED_BACKUP, this.onSeedBackup) this.socket.on(IS_GUN_AUTH, this.isGunAuth) + + this.socket.on('SET_LAST_SEEN_APP', async body => { + try { + await throwOnInvalidToken(body.token) + await new Promise((res, rej) => { + getUser() + .get('lastSeenApp') + .put(Date.now(), ack => { + if (ack.err) { + rej(new Error(ack.err)) + } else { + res() + } + }) + }) + this.socket.emit('SET_LAST_SEEN_APP', { + ok: true, + msg: null, + origBody: body + }) + } catch (e) { + this.socket.emit('SET_LAST_SEEN_APP', { + ok: false, + msg: e.message, + origBody: body + }) + } + }) } /** @param {SimpleSocket} socket */ diff --git a/utils/encryptionStore.js b/utils/encryptionStore.js index d00e93de..411508f8 100644 --- a/utils/encryptionStore.js +++ b/utils/encryptionStore.js @@ -6,7 +6,12 @@ const { Buffer } = require('buffer') const APIKeyPair = new Map() const authorizedDevices = new Map() -const nonEncryptedEvents = ['ping', 'disconnect', 'IS_GUN_AUTH'] +const nonEncryptedEvents = [ + 'ping', + 'disconnect', + 'IS_GUN_AUTH', + 'SET_LAST_SEEN_APP' +] const Encryption = { isNonEncrypted: event => nonEncryptedEvents.includes(event),