spin up events at login

This commit is contained in:
Daniel Lugo 2020-07-22 17:34:01 -04:00
parent e1e6b87981
commit ef31b0c375
2 changed files with 40 additions and 47 deletions

View file

@ -324,6 +324,18 @@ const authenticate = async (alias, pass, __user) => {
API.Jobs.onAcceptedRequests(_user, mySEA)
API.Jobs.onOrders(_user, gun, mySEA)
API.Jobs.lastSeenNode(_user)
API.Events.onAvatar(() => {}, user)()
API.Events.onBio(() => {}, user)
API.Events.onBlacklist(() => {}, user)
API.Events.onChats(() => {})()
API.Events.onCurrentHandshakeAddress(() => {}, user)()
API.Events.onDisplayName(() => {}, user)()
API.Events.onOutgoing(() => {})()
API.Events.onSeedBackup(() => {}, user, mySEA)
API.Events.onSimplerReceivedRequests(() => {})()
API.Events.onSimplerSentRequests(() => {})()
return _user._.sea.pub
}
@ -372,6 +384,17 @@ const authenticate = async (alias, pass, __user) => {
API.Jobs.onOrders(_user, gun, mySEA)
API.Jobs.lastSeenNode(_user)
API.Events.onAvatar(() => {}, user)()
API.Events.onBio(() => {}, user)
API.Events.onBlacklist(() => {}, user)
API.Events.onChats(() => {})()
API.Events.onCurrentHandshakeAddress(() => {}, user)()
API.Events.onDisplayName(() => {}, user)()
API.Events.onOutgoing(() => {})()
API.Events.onSeedBackup(() => {}, user, mySEA)
API.Events.onSimplerReceivedRequests(() => {})()
API.Events.onSimplerSentRequests(() => {})()
return ack.sea.pub
} else {
logger.error(

View file

@ -1718,14 +1718,9 @@ module.exports = async (
app.get(`/api/gun/${GunEvent.ON_RECEIVED_REQUESTS}`, (_, res) => {
try {
// spinup
Events.onSimplerReceivedRequests(() => {})()
// ensure event data gets updated before fetching it
process.nextTick(() => {
const data = Events.getCurrentReceivedReqs()
res.json({
data,
})
const data = Events.getCurrentReceivedReqs()
res.json({
data,
})
} catch (err) {
logger.info('Error in Received Requests poll:')
@ -1738,16 +1733,10 @@ module.exports = async (
app.get(`/api/gun/${GunEvent.ON_SENT_REQUESTS}`, (_, res) => {
try {
// spinup
Events.onSimplerSentRequests(() => {})()
// ensure event data gets updated before fetching it
process.nextTick(() => {
const data = Events.getCurrentSentReqs()
logger.info(`Sent requests poll: ${JSON.stringify(data, null, 4)}`)
res.json({
data,
})
const data = Events.getCurrentSentReqs()
logger.info(`Sent requests poll: ${JSON.stringify(data, null, 4)}`)
res.json({
data,
})
} catch (err) {
logger.info('Error in sentRequests poll:')
@ -1760,16 +1749,10 @@ module.exports = async (
app.get(`/api/gun/${GunEvent.ON_CHATS}`, (_, res) => {
try {
// spinup
Events.onChats(() => {})()
// ensure event data gets updated before fetching it
process.nextTick(() => {
const data = Events.getChats()
logger.info(`Chats polled: ${data.length}`)
res.json({
data,
})
const data = Events.getChats()
logger.info(`Chats polled: ${data.length}`)
res.json({
data,
})
} catch (err) {
logger.info('Error in Chats poll:')
@ -2140,15 +2123,9 @@ module.exports = async (
*/
const apiGunRequestsReceivedGet = (_, res) => {
try {
// spinup
Events.onSimplerReceivedRequests(() => {})()
// ensure event data gets updated before fetching it
process.nextTick(() => {
const data = Events.getCurrentReceivedReqs()
res.json({
data,
})
const data = Events.getCurrentReceivedReqs()
res.json({
data,
})
} catch (err) {
logger.error(err)
@ -2163,16 +2140,9 @@ module.exports = async (
*/
const apiGunRequestsSentGet = (_, res) => {
try {
// spinup
Events.onSimplerSentRequests(() => {})()
// ensure event data gets updated before fetching it
process.nextTick(() => {
const data = Events.getCurrentSentReqs()
res.json({
data,
})
const data = Events.getCurrentSentReqs()
res.json({
data,
})
} catch (err) {
logger.error(err)