@@ -4,7 +4,7 @@ import { useAuthStore } from "@/stores/auth-store";
|
||||
import { parseParticlePath, type ParticlePath } from "@/lib/particle-path";
|
||||
import type { Particle, StreamProperties } from "@/api/types";
|
||||
import { where, Timestamp } from "firebase/firestore";
|
||||
import { RECENCY_WINDOW_HOURS } from "@/lib/constants";
|
||||
import { useNetwork } from "@/hooks/use-networks";
|
||||
|
||||
type StreamParticle = Particle & { type: "stream"; properties: StreamProperties };
|
||||
|
||||
@@ -27,21 +27,28 @@ export function useStreamParticles(path: ParticlePath): UseStreamParticlesResult
|
||||
const { networkId } = parseParticlePath(path);
|
||||
const user = useAuthStore((s) => s.user);
|
||||
const visibilityScopes = useVisibilityScopes(user?.id, networkId);
|
||||
const network = useNetwork(networkId);
|
||||
const retentionHours = network?.message_retention_hours ?? 24;
|
||||
|
||||
const [recencyCutoff, setRecencyCutoff] = useState(() => {
|
||||
const d = new Date();
|
||||
d.setHours(d.getHours() - RECENCY_WINDOW_HOURS);
|
||||
d.setHours(d.getHours() - retentionHours);
|
||||
return Timestamp.fromDate(d);
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
// Recalculate immediately when retention changes
|
||||
const d = new Date();
|
||||
d.setHours(d.getHours() - retentionHours);
|
||||
setRecencyCutoff(Timestamp.fromDate(d));
|
||||
|
||||
const interval = setInterval(() => {
|
||||
const d = new Date();
|
||||
d.setHours(d.getHours() - RECENCY_WINDOW_HOURS);
|
||||
d.setHours(d.getHours() - retentionHours);
|
||||
setRecencyCutoff(Timestamp.fromDate(d));
|
||||
}, 60 * 60 * 1000);
|
||||
return () => clearInterval(interval);
|
||||
}, []);
|
||||
}, [retentionHours]);
|
||||
|
||||
const { children, isLoading } = useLiveParticleChildren(
|
||||
path,
|
||||
|
||||
Reference in New Issue
Block a user