From a4f476998948a78ceae86934d6f4de4df4be029b Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Tue, 4 Feb 2020 18:08:47 -0400 Subject: [PATCH] debounce, remove console logs --- services/gunDB/Mediator/index.js | 35 ++++++++++++--------------- services/gunDB/contact-api/actions.js | 11 ++++----- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/services/gunDB/Mediator/index.js b/services/gunDB/Mediator/index.js index 5ad2c8bc..938dbaa7 100644 --- a/services/gunDB/Mediator/index.js +++ b/services/gunDB/Mediator/index.js @@ -372,16 +372,9 @@ class Mediator { console.error('Unknown Device', error) return false } - console.log('Emitting Data...', data) if (typeof data === 'string') { data = JSON.parse(data) } - console.log('Event:', eventName) - console.log('Data:', data) - console.log('Decrypt params:', { - deviceId, - message: data.encryptedKey - }) const decryptedKey = Encryption.decryptKey({ deviceId, message: data.encryptedKey @@ -415,7 +408,7 @@ class Mediator { deviceId }) : data - console.log('Sending Message...', eventName, data, encryptedMessage) + socket.emit(eventName, encryptedMessage) } catch (err) { console.error(err) @@ -928,19 +921,21 @@ class Mediator { await throwOnInvalidToken(token) - await API.Events.onSimplerSentRequests(sentRequests => { - if (Config.SHOW_LOG) { - console.log('---sentRequests---') - console.log(sentRequests) - console.log('-----------------------') - } + await API.Events.onSimplerSentRequests( + debounce(sentRequests => { + if (Config.SHOW_LOG) { + console.log('---sentRequests---') + console.log(sentRequests) + console.log('-----------------------') + } - this.socket.emit(Event.ON_SENT_REQUESTS, { - msg: sentRequests, - ok: true, - origBody: body - }) - }) + this.socket.emit(Event.ON_SENT_REQUESTS, { + msg: sentRequests, + ok: true, + origBody: body + }) + }, 200) + ) } catch (err) { console.log(err) this.socket.emit(Event.ON_SENT_REQUESTS, { diff --git a/services/gunDB/contact-api/actions.js b/services/gunDB/contact-api/actions.js index c5643b8a..d74f33fa 100644 --- a/services/gunDB/contact-api/actions.js +++ b/services/gunDB/contact-api/actions.js @@ -514,6 +514,11 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => { timestamp } + const encryptedForMeRecipientPublicKey = await SEA.encrypt( + recipientPublicKey, + mySecret + ) + console.log('sendHR() -> before newHandshakeRequestID') /** @type {string} */ const newHandshakeRequestID = await new Promise((res, rej) => { @@ -542,14 +547,8 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => { }) }) - const encryptedForMeRecipientPublicKey = await SEA.encrypt( - recipientPublicKey, - mySecret - ) - // This needs to come before the write to sent requests. Because that write // triggers Jobs.onAcceptedRequests and it in turn reads from request-to-user - // This also triggers Events.onSimplerSentRequests /** * @type {StoredReq}