fix(mobile): recover pending questions after cold start
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
useSessionMessageLoader,
|
||||
useSyncDirectory,
|
||||
useSyncSDK,
|
||||
resyncBlockingRequestsForDirectory,
|
||||
} from "./sync-context"
|
||||
import { dropSessionCaches, getProtectedSessionCacheIds } from "./session-cache"
|
||||
import { stripSessionDiffSnapshots } from "./sanitize"
|
||||
@@ -123,6 +124,23 @@ export function useSync() {
|
||||
const messageLoader = useSessionMessageLoader()
|
||||
const runtimeKey = getRuntimeKey()
|
||||
|
||||
const recoverPendingQuestions = useCallback(
|
||||
async (sessionID: string, directoryOverride?: string): Promise<boolean> => {
|
||||
const targetDirectory = directoryOverride || directory
|
||||
if (!sessionID || !targetDirectory || getRuntimeKey() !== runtimeKey) return false
|
||||
const targetStore = childStores.ensureChild(targetDirectory, {
|
||||
priority: "selected",
|
||||
reason: "selected-session",
|
||||
})
|
||||
await resyncBlockingRequestsForDirectory(targetDirectory, targetStore, [sessionID], {
|
||||
includePermissions: false,
|
||||
})
|
||||
if (getRuntimeKey() !== runtimeKey) return false
|
||||
return (targetStore.getState().question[sessionID]?.length ?? 0) > 0
|
||||
},
|
||||
[childStores, directory, runtimeKey],
|
||||
)
|
||||
|
||||
const keyFor = useCallback(
|
||||
(sessionID: string, directoryOverride = directory) => `${runtimeKey}\n${directoryOverride}\n${sessionID}`,
|
||||
[directory, runtimeKey],
|
||||
@@ -408,12 +426,13 @@ export function useSync() {
|
||||
hasMore,
|
||||
isLoading,
|
||||
isComplete,
|
||||
recoverPendingQuestions,
|
||||
optimistic: {
|
||||
add: optimisticAdd,
|
||||
remove: optimisticRemove,
|
||||
confirm: optimisticConfirm,
|
||||
},
|
||||
}),
|
||||
[syncSession, prefetchSession, loadMore, loadCompleteHistory, hasMore, isLoading, isComplete, optimisticAdd, optimisticRemove, optimisticConfirm],
|
||||
[syncSession, prefetchSession, loadMore, loadCompleteHistory, hasMore, isLoading, isComplete, recoverPendingQuestions, optimisticAdd, optimisticRemove, optimisticConfirm],
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user