summaryrefslogtreecommitdiffhomepage
path: root/packages/app/src/context
diff options
context:
space:
mode:
Diffstat (limited to 'packages/app/src/context')
-rw-r--r--packages/app/src/context/sync.tsx20
1 files changed, 19 insertions, 1 deletions
diff --git a/packages/app/src/context/sync.tsx b/packages/app/src/context/sync.tsx
index 7138c4ab4..e5f2c076e 100644
--- a/packages/app/src/context/sync.tsx
+++ b/packages/app/src/context/sync.tsx
@@ -30,6 +30,22 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
return undefined
}
+ const limitFor = (count: number) => {
+ if (count <= chunk) return chunk
+ return Math.ceil(count / chunk) * chunk
+ }
+
+ const hydrateMessages = (sessionID: string) => {
+ if (meta.limit[sessionID] !== undefined) return
+
+ const messages = store.message[sessionID]
+ if (!messages) return
+
+ const limit = limitFor(messages.length)
+ setMeta("limit", sessionID, limit)
+ setMeta("complete", sessionID, messages.length < limit)
+ }
+
const loadMessages = async (sessionID: string, limit: number) => {
if (meta.loading[sessionID]) return
@@ -118,7 +134,9 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
},
async sync(sessionID: string) {
const hasSession = getSession(sessionID) !== undefined
- const hasMessages = store.message[sessionID] !== undefined && meta.limit[sessionID] !== undefined
+ hydrateMessages(sessionID)
+
+ const hasMessages = store.message[sessionID] !== undefined
if (hasSession && hasMessages) return
const pending = inflight.get(sessionID)