ensure follows sub graph is always initialized and non-empty
This commit is contained in:
parent
fc375be37f
commit
b1515bfd9d
1 changed files with 48 additions and 0 deletions
|
|
@ -12,6 +12,8 @@ require('gun/lib/load')
|
|||
const debounce = require('lodash/debounce')
|
||||
const Encryption = require('../../../utils/encryptionStore')
|
||||
|
||||
const Key = require('../contact-api/key')
|
||||
|
||||
/** @type {import('../contact-api/SimpleGUN').ISEA} */
|
||||
// @ts-ignore
|
||||
const SEAx = require('gun/sea')
|
||||
|
|
@ -267,6 +269,21 @@ const authenticate = async (alias, pass, __user) => {
|
|||
if (typeof ack.err === 'string') {
|
||||
throw new Error(ack.err)
|
||||
} else if (typeof ack.sea === 'object') {
|
||||
await new Promise((res, rej) => {
|
||||
_user.get(Key.FOLLOWS).put(
|
||||
{
|
||||
unused: null
|
||||
},
|
||||
ack => {
|
||||
if (ack.err) {
|
||||
rej(new Error(`Error initializing follows: ${ack.err}`))
|
||||
} else {
|
||||
res()
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
return ack.sea.pub
|
||||
} else {
|
||||
throw new Error('Unknown error.')
|
||||
|
|
@ -279,6 +296,22 @@ const authenticate = async (alias, pass, __user) => {
|
|||
`Tried to re-authenticate with an alias different to that of stored one, tried: ${alias} - stored: ${_currentAlias}, logoff first if need to change aliases.`
|
||||
)
|
||||
}
|
||||
|
||||
await new Promise((res, rej) => {
|
||||
_user.get(Key.FOLLOWS).put(
|
||||
{
|
||||
unused: null
|
||||
},
|
||||
ack => {
|
||||
if (ack.err) {
|
||||
rej(new Error(`Error initializing follows: ${ack.err}`))
|
||||
} else {
|
||||
res()
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
// move this to a subscription; implement off() ? todo
|
||||
API.Jobs.onAcceptedRequests(_user, mySEA)
|
||||
API.Jobs.onOrders(_user, gun, mySEA)
|
||||
|
|
@ -312,6 +345,21 @@ const authenticate = async (alias, pass, __user) => {
|
|||
|
||||
await new Promise(res => setTimeout(res, 5000))
|
||||
|
||||
await new Promise((res, rej) => {
|
||||
_user.get(Key.FOLLOWS).put(
|
||||
{
|
||||
unused: null
|
||||
},
|
||||
ack => {
|
||||
if (ack.err) {
|
||||
rej(new Error(`Error initializing follows: ${ack.err}`))
|
||||
} else {
|
||||
res()
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
API.Jobs.onAcceptedRequests(_user, mySEA)
|
||||
API.Jobs.onOrders(_user, gun, mySEA)
|
||||
API.Jobs.lastSeenNode(_user)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue