set last seen action

This commit is contained in:
Daniel Lugo 2020-02-19 00:21:36 -04:00
parent 788e40c84e
commit 1d9215c7f6
2 changed files with 34 additions and 1 deletions

View file

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

View file

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