2021-08-17 18:15:24 +00:00
|
|
|
export const LIMIT = 21
|
|
|
|
|
|
|
|
export function decodeCursor (cursor) {
|
|
|
|
if (!cursor) {
|
|
|
|
return { offset: 0, time: new Date() }
|
|
|
|
} else {
|
|
|
|
const res = JSON.parse(Buffer.from(cursor, 'base64'))
|
|
|
|
res.time = new Date(res.time)
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-04 20:10:56 +00:00
|
|
|
export function nextCursorEncoded (cursor, limit = LIMIT) {
|
|
|
|
cursor.offset += limit
|
2021-08-17 18:15:24 +00:00
|
|
|
return Buffer.from(JSON.stringify(cursor)).toString('base64')
|
|
|
|
}
|
2024-03-06 19:53:13 +00:00
|
|
|
|
|
|
|
export function nextNoteCursorEncoded (cursor, notifications = [], limit = LIMIT) {
|
|
|
|
// what we are looking for this oldest sort time for every table we are looking at
|
|
|
|
cursor.time = new Date(notifications.slice(-1).pop()?.sortTime ?? cursor.time)
|
|
|
|
cursor.offset += limit
|
|
|
|
return Buffer.from(JSON.stringify(cursor)).toString('base64')
|
|
|
|
}
|