fix: prevent playback marker going back in time

Closes #141
This commit is contained in:
talksik
2026-04-09 17:02:50 -07:00
parent 762c0ccf6e
commit 4d9a415981
+12 -2
View File
@@ -178,12 +178,22 @@ export function useStreamPlayback(
return () => clearTimeout(timeout);
}, [children, streamParticle.id, streamParticle.playback_markers, userId, state.initialized]);
// --- Persist playback marker ---
// --- Persist playback marker (only advance forward, never backwards) ---
const lastPersistedMarkerRef = useRef<Date | null>(null);
useEffect(() => {
if (!userId || !state.initialized || !currentParticle) return;
const currentTime = currentParticle.created_at;
const existingMarker =
lastPersistedMarkerRef.current ?? streamParticle.playback_markers?.[userId];
// Only update if advancing beyond the current marker
if (existingMarker && currentTime.getTime() <= existingMarker.getTime()) return;
lastPersistedMarkerRef.current = currentTime;
const streamDocPath = toFirestoreDocPath(path);
updateStreamPlaybackMarker(streamDocPath, userId, currentParticle.created_at);
updateStreamPlaybackMarker(streamDocPath, userId, currentTime);
}, [currentParticle?.id, state.initialized, userId, path]);
// --- Navigation callbacks ---