From db884955fe99a11702249e978ad6366a26943868 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Sat, 25 Jan 2020 16:46:02 -0400 Subject: [PATCH] didDisconnect util --- services/gunDB/contact-api/utils/index.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/services/gunDB/contact-api/utils/index.js b/services/gunDB/contact-api/utils/index.js index 9e4d10e6..6a393f8a 100644 --- a/services/gunDB/contact-api/utils/index.js +++ b/services/gunDB/contact-api/utils/index.js @@ -1,7 +1,7 @@ /** * @format */ -const { getUser, mySEA: SEA } = require('../../Mediator') +const { getUser, mySEA: SEA, getGun } = require('../../Mediator') const ErrorCode = require('../errorCode') const Key = require('../key') @@ -288,6 +288,21 @@ const dataHasSoul = listenerData => */ const defaultName = pub => 'anon' + pub.slice(0, 8) +/** + * @param {string} pub + * @param {string} incomingID + * @returns {Promise} + */ +const didDisconnect = async (pub, incomingID) => { + const feed = await getGun() + .user(pub) + .get(Key.OUTGOINGS) + .get(incomingID) + .then() + + return feed === null +} + module.exports = { asyncMap, asyncFilter, @@ -303,5 +318,6 @@ module.exports = { currHandshakeAddress, tryAndWait, mySecret, - promisifyGunNode: require('./promisifygun') + promisifyGunNode: require('./promisifygun'), + didDisconnect }