From d5b9a233569e5b2c949aea9415dda38f378912c6 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Sat, 18 Apr 2020 14:37:16 -0400 Subject: [PATCH] factor out setLastSeenApp() --- services/gunDB/Mediator/index.js | 37 +++++++++++++++++--------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/services/gunDB/Mediator/index.js b/services/gunDB/Mediator/index.js index e213643d..4a3cafa4 100644 --- a/services/gunDB/Mediator/index.js +++ b/services/gunDB/Mediator/index.js @@ -441,23 +441,7 @@ class Mediator { this.socket.on(IS_GUN_AUTH, this.isGunAuth) - this.socket.on(Action.SET_LAST_SEEN_APP, async body => { - try { - await throwOnInvalidToken(body.token) - await API.Actions.setLastSeenApp() - this.socket.emit(Action.SET_LAST_SEEN_APP, { - ok: true, - msg: null, - origBody: body - }) - } catch (e) { - this.socket.emit(Action.SET_LAST_SEEN_APP, { - ok: false, - msg: e.message, - origBody: body - }) - } - }) + this.socket.on(Action.SET_LAST_SEEN_APP, this.setLastSeenApp) } /** @param {SimpleSocket} socket */ @@ -543,6 +527,25 @@ class Mediator { } } + /** @param {{ token: string }} body */ + setLastSeenApp = async body => { + try { + await throwOnInvalidToken(body.token) + await API.Actions.setLastSeenApp() + this.socket.emit(Action.SET_LAST_SEEN_APP, { + ok: true, + msg: null, + origBody: body + }) + } catch (e) { + this.socket.emit(Action.SET_LAST_SEEN_APP, { + ok: false, + msg: e.message, + origBody: body + }) + } + } + isGunAuth = () => { try { const isGunAuth = isAuthenticated()