Simplify last seen
This commit is contained in:
parent
a1320fa14c
commit
4b05bc014e
2 changed files with 10 additions and 58 deletions
|
|
@ -760,42 +760,14 @@ const saveChannelsBackup = async (backups, user, SEA) => {
|
||||||
/**
|
/**
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
const setLastSeenApp = () =>
|
const setLastSeenApp = () => {
|
||||||
/** @type {Promise<void>} */ (new Promise((res, rej) => {
|
const user = require('../Mediator').getUser()
|
||||||
require('../Mediator')
|
|
||||||
.getUser()
|
return user
|
||||||
.get(Key.LAST_SEEN_APP)
|
|
||||||
.put(Date.now(), ack => {
|
|
||||||
if (
|
|
||||||
ack.err &&
|
|
||||||
typeof ack.err !== 'number' &&
|
|
||||||
typeof ack.err !== 'object'
|
|
||||||
) {
|
|
||||||
rej(new Error(ack.err))
|
|
||||||
} else {
|
|
||||||
res()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})).then(
|
|
||||||
() =>
|
|
||||||
new Promise((res, rej) => {
|
|
||||||
require('../Mediator')
|
|
||||||
.getUser()
|
|
||||||
.get(Key.PROFILE)
|
.get(Key.PROFILE)
|
||||||
.get(Key.LAST_SEEN_APP)
|
.get(Key.LAST_SEEN_APP)
|
||||||
.put(Date.now(), ack => {
|
.pPut(Date.now())
|
||||||
if (
|
}
|
||||||
ack.err &&
|
|
||||||
typeof ack.err !== 'number' &&
|
|
||||||
typeof ack.err !== 'object'
|
|
||||||
) {
|
|
||||||
rej(new Error(ack.err))
|
|
||||||
} else {
|
|
||||||
res()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string[]} tags
|
* @param {string[]} tags
|
||||||
|
|
|
||||||
|
|
@ -27,32 +27,12 @@ const Key = require('../key')
|
||||||
*/
|
*/
|
||||||
const lastSeenNode = user => {
|
const lastSeenNode = user => {
|
||||||
if (!user.is) {
|
if (!user.is) {
|
||||||
logger.warn('onOrders() -> tried to sub without authing')
|
logger.warn('lastSeenNode() -> tried to sub without authing')
|
||||||
throw new Error(ErrorCode.NOT_AUTH)
|
throw new Error(ErrorCode.NOT_AUTH)
|
||||||
}
|
}
|
||||||
let gotLatestUserAck = true
|
|
||||||
let gotLatestProfileAck = true
|
let gotLatestProfileAck = true
|
||||||
|
|
||||||
setInterval(() => {
|
|
||||||
if (!user.is) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!gotLatestUserAck) {
|
|
||||||
logger.error(`lastSeenNode user job: didnt get latest ack`)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
gotLatestUserAck = false
|
|
||||||
user.get(Key.LAST_SEEN_NODE).put(Date.now(), ack => {
|
|
||||||
if (
|
|
||||||
ack.err &&
|
|
||||||
typeof ack.err !== 'number' &&
|
|
||||||
typeof ack.err !== 'object'
|
|
||||||
) {
|
|
||||||
logger.error(`Error inside lastSeenNode user job: ${ack.err}`)
|
|
||||||
}
|
|
||||||
gotLatestUserAck = true
|
|
||||||
})
|
|
||||||
}, LAST_SEEN_NODE_INTERVAL)
|
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
if (!user.is) {
|
if (!user.is) {
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue