Merge pull request #97 from shocknet/follows-init-hotfix
ensure follows sub graph is always initialized and non-empty
This commit is contained in:
commit
5bb5d7855f
2 changed files with 55 additions and 8 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)
|
||||
|
|
|
|||
|
|
@ -1906,12 +1906,11 @@ module.exports = async (
|
|||
/**
|
||||
* @type {RequestHandler<FollowsRouteParams>}
|
||||
*/
|
||||
const apiGunFollowsGet = (_, res) => {
|
||||
const apiGunFollowsGet = async (_, res) => {
|
||||
try {
|
||||
// const { publicKey } = req.params;
|
||||
// const currFollows = await GunGetters.currentFollows()
|
||||
const currFollows = await GunGetters.Follows.currentFollows()
|
||||
|
||||
return res.status(200).json({})
|
||||
return res.status(200).json(currFollows)
|
||||
} catch (err) {
|
||||
return res.status(500).json({
|
||||
errorMessage: err.message || 'Unknown ERR at GET /api/follows'
|
||||
|
|
@ -1923,14 +1922,14 @@ module.exports = async (
|
|||
/**
|
||||
* @type {RequestHandler<FollowsRouteParams>}
|
||||
*/
|
||||
const apiGunFollowsPut = (req, res) => {
|
||||
const apiGunFollowsPut = async (req, res) => {
|
||||
try {
|
||||
const { publicKey } = req.params;
|
||||
if (!publicKey) {
|
||||
throw new Error(`Missing publicKey route param.`)
|
||||
}
|
||||
|
||||
// await GunActions.follow(req.params.publicKey, false)
|
||||
await GunActions.follow(req.params.publicKey, false)
|
||||
|
||||
// 201 would be extraneous here. Implement it inside app.put
|
||||
return res.status(200).json({
|
||||
|
|
@ -1946,14 +1945,14 @@ module.exports = async (
|
|||
/**
|
||||
* @type {RequestHandler<FollowsRouteParams>}
|
||||
*/
|
||||
const apiGunFollowsDelete = (req, res) => {
|
||||
const apiGunFollowsDelete = async (req, res) => {
|
||||
try {
|
||||
const { publicKey } = req.params;
|
||||
if (!publicKey) {
|
||||
throw new Error(`Missing publicKey route param.`)
|
||||
}
|
||||
|
||||
// await GunActions.unfollow(req.params.publicKey)
|
||||
await GunActions.unfollow(req.params.publicKey)
|
||||
|
||||
return res.status(200).json({
|
||||
ok: true
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue