From 411fb82df9535d603d0b2b52dbcce3cc17660a45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nicole=20miko=C5=82ajczyk?= Date: Thu, 5 Mar 2026 21:57:20 +0100 Subject: [PATCH] nicolium: do not restore timeline from index===0 until 15 minutes passed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: nicole mikołajczyk --- packages/nicolium/src/columns/timeline.tsx | 42 ++++++++++++++++++---- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/packages/nicolium/src/columns/timeline.tsx b/packages/nicolium/src/columns/timeline.tsx index 2593cd59f..9490f61cd 100644 --- a/packages/nicolium/src/columns/timeline.tsx +++ b/packages/nicolium/src/columns/timeline.tsx @@ -517,18 +517,48 @@ const Timeline: React.FC = ({ ); }; +const savePosition = (me: string, entry: TimelineEntry, index: number) => { + if (entry.type !== 'status') return; + return localStorage.setItem( + `nicolium:${me}:homeTimelinePosition`, + `${entry.originalId}|${index}|${Date.now()}`, + ); +}; + +const getRestoredPosition = (me: string) => { + const markerKey = `nicolium:${me}:homeTimelinePosition`; + const marker = localStorage.getItem(markerKey); + if (!marker) return null; + + return marker.split('|'); +}; + const HomeTimelineColumn: React.FC = (props) => { const me = useAppSelector((state) => state.me); - const marker = `nicolium:${me}:homeTimelinePosition`; - const restoredPosition = useRef(localStorage.getItem(marker)); - const timelineQuery = useHomeTimeline(undefined, restoredPosition.current || undefined); + const maxId = useMemo(() => { + if (!me) return undefined; + + const position = getRestoredPosition(me); + + if (!position) return undefined; + + if (position[1] === '0') { + const timeDifference = Date.now() - parseInt(position[2], 10); + + if (timeDifference > 15 * 60 * 1000) { + return position[0]; + } + return undefined; + } + return position[0]; + }, []); + + const timelineQuery = useHomeTimeline(undefined, maxId); const handleTopItemChanged = (index: number) => { const entry = timelineQuery.entries[index]; - if (index === 0) return localStorage.removeItem(marker); - if (!entry || entry.type !== 'status') return; - localStorage.setItem(marker, entry.originalId); + if (me) savePosition(me, entry, index); }; return (