cleanup()
This commit is contained in:
parent
56a9caf8c1
commit
8f7792f275
1 changed files with 69 additions and 56 deletions
|
|
@ -384,6 +384,72 @@ const generateHandshakeAddress = async () => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {string} pub
|
||||||
|
* @throws {Error}
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
const cleanup = async pub => {
|
||||||
|
const user = require('../Mediator').getUser()
|
||||||
|
|
||||||
|
const outGoingID = await Utils.recipientToOutgoingID(pub)
|
||||||
|
|
||||||
|
await new Promise((res, rej) => {
|
||||||
|
user
|
||||||
|
.get(Key.USER_TO_INCOMING)
|
||||||
|
.get(pub)
|
||||||
|
.put(null, ack => {
|
||||||
|
if (ack.err) {
|
||||||
|
rej(new Error(ack.err))
|
||||||
|
} else {
|
||||||
|
res()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
await new Promise((res, rej) => {
|
||||||
|
user
|
||||||
|
.get(Key.RECIPIENT_TO_OUTGOING)
|
||||||
|
.get(pub)
|
||||||
|
.put(null, ack => {
|
||||||
|
if (ack.err) {
|
||||||
|
rej(new Error(ack.err))
|
||||||
|
} else {
|
||||||
|
res()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
await new Promise((res, rej) => {
|
||||||
|
user
|
||||||
|
.get(Key.USER_TO_LAST_REQUEST_SENT)
|
||||||
|
.get(pub)
|
||||||
|
.put(null, ack => {
|
||||||
|
if (ack.err) {
|
||||||
|
rej(new Error(ack.err))
|
||||||
|
} else {
|
||||||
|
res()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
if (outGoingID) {
|
||||||
|
await new Promise((res, rej) => {
|
||||||
|
user
|
||||||
|
.get(Key.OUTGOINGS)
|
||||||
|
.get(outGoingID)
|
||||||
|
.put(null, ack => {
|
||||||
|
if (ack.err) {
|
||||||
|
rej(new Error(ack.err))
|
||||||
|
} else {
|
||||||
|
res()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} recipientPublicKey
|
* @param {string} recipientPublicKey
|
||||||
* @param {GUNNode} gun
|
* @param {GUNNode} gun
|
||||||
|
|
@ -397,6 +463,8 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => {
|
||||||
throw new Error(ErrorCode.NOT_AUTH)
|
throw new Error(ErrorCode.NOT_AUTH)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await cleanup(recipientPublicKey)
|
||||||
|
|
||||||
if (typeof recipientPublicKey !== 'string') {
|
if (typeof recipientPublicKey !== 'string') {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
`recipientPublicKey is not string, got: ${typeof recipientPublicKey}`
|
`recipientPublicKey is not string, got: ${typeof recipientPublicKey}`
|
||||||
|
|
@ -1037,66 +1105,11 @@ const saveSeedBackup = async (mnemonicPhrase, user, SEA) => {
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
const disconnect = async pub => {
|
const disconnect = async pub => {
|
||||||
const user = require('../Mediator').getUser()
|
|
||||||
if (!(await Utils.successfulHandshakeAlreadyExists(pub))) {
|
if (!(await Utils.successfulHandshakeAlreadyExists(pub))) {
|
||||||
throw new Error('No handshake exists for this pub')
|
throw new Error('No handshake exists for this pub')
|
||||||
}
|
}
|
||||||
|
|
||||||
const outGoingID = /** @type {string} */ (await Utils.recipientToOutgoingID(
|
await cleanup(pub)
|
||||||
pub
|
|
||||||
))
|
|
||||||
|
|
||||||
await new Promise((res, rej) => {
|
|
||||||
user
|
|
||||||
.get(Key.USER_TO_INCOMING)
|
|
||||||
.get(pub)
|
|
||||||
.put(null, ack => {
|
|
||||||
if (ack.err) {
|
|
||||||
rej(new Error(ack.err))
|
|
||||||
} else {
|
|
||||||
res()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
await new Promise((res, rej) => {
|
|
||||||
user
|
|
||||||
.get(Key.RECIPIENT_TO_OUTGOING)
|
|
||||||
.get(pub)
|
|
||||||
.put(null, ack => {
|
|
||||||
if (ack.err) {
|
|
||||||
rej(new Error(ack.err))
|
|
||||||
} else {
|
|
||||||
res()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
await new Promise((res, rej) => {
|
|
||||||
user
|
|
||||||
.get(Key.USER_TO_LAST_REQUEST_SENT)
|
|
||||||
.get(pub)
|
|
||||||
.put(null, ack => {
|
|
||||||
if (ack.err) {
|
|
||||||
rej(new Error(ack.err))
|
|
||||||
} else {
|
|
||||||
res()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
await new Promise((res, rej) => {
|
|
||||||
user
|
|
||||||
.get(Key.OUTGOINGS)
|
|
||||||
.get(outGoingID)
|
|
||||||
.put(null, ack => {
|
|
||||||
if (ack.err) {
|
|
||||||
rej(new Error(ack.err))
|
|
||||||
} else {
|
|
||||||
res()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
await generateHandshakeAddress()
|
await generateHandshakeAddress()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue