From 5a20698f878562cf5989847792883883609a3e84 Mon Sep 17 00:00:00 2001 From: hzrd149 Date: Tue, 4 Jul 2023 13:09:13 -0500 Subject: [PATCH] fix showing duplicate streams --- src/views/streams/index.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/views/streams/index.tsx b/src/views/streams/index.tsx index 07489988c..f951326c7 100644 --- a/src/views/streams/index.tsx +++ b/src/views/streams/index.tsx @@ -6,7 +6,7 @@ import IntersectionObserverProvider from "../../providers/intersection-observer" import { useTimelineCurserIntersectionCallback } from "../../hooks/use-timeline-cursor-intersection-callback"; import useSubject from "../../hooks/use-subject"; import StreamCard from "./components/stream-card"; -import { ParsedStream, parseStreamEvent } from "../../helpers/nostr/stream"; +import { ParsedStream, getATag, parseStreamEvent } from "../../helpers/nostr/stream"; import { NostrEvent } from "../../types/nostr-event"; export default function LiveStreamsTab() { @@ -29,13 +29,17 @@ export default function LiveStreamsTab() { const events = useSubject(timeline.timeline); const streams = useMemo(() => { - const parsed: ParsedStream[] = []; + const parsedStreams: Record = {}; for (const event of events) { try { - parsed.push(parseStreamEvent(event)); + const parsed = parseStreamEvent(event); + const aTag = getATag(parsed); + if (!parsedStreams[aTag] || parsed.event.created_at > parsedStreams[aTag].event.created_at) { + parsedStreams[aTag] = parsed; + } } catch (e) {} } - return parsed.sort((a, b) => b.updated - a.updated); + return Array.from(Object.values(parsedStreams)).sort((a, b) => b.updated - a.updated); }, [events]); return (