@@ -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 ---
|
||||
|
||||
Reference in New Issue
Block a user