diff --git a/src/element/live-chat.tsx b/src/element/live-chat.tsx index b049c77..fb917bd 100644 --- a/src/element/live-chat.tsx +++ b/src/element/live-chat.tsx @@ -8,6 +8,7 @@ import { parseZap, encodeTLV, } from "@snort/system"; +import { unixNow } from "@snort/shared"; import { useEffect, useMemo } from "react"; import uniqBy from "lodash.uniqby"; @@ -28,7 +29,7 @@ import { useLogin } from "hooks/login"; import useTopZappers from "hooks/top-zappers"; import { useAddress } from "hooks/event"; import { formatSats } from "number"; -import { LIVE_STREAM_CHAT } from "const"; +import { WEEK, LIVE_STREAM_CHAT } from "const"; import { findTag, getTagValues, getHost } from "utils"; import { System } from "index"; @@ -91,7 +92,6 @@ export function LiveChat({ height?: number; }) { const host = getHost(ev); - const { badges, awards } = useBadges(host); const feed = useLiveChatFeed(link, goal ? [goal.id] : undefined); const login = useLogin(); useEffect(() => { @@ -101,6 +101,11 @@ export function LiveChat({ System.ProfileLoader.TrackMetadata(pubkeys); return () => System.ProfileLoader.UntrackMetadata(pubkeys); }, [feed.zaps]); + const started = useMemo(() => { + const starts = findTag(ev, "starts"); + return starts ? Number(starts) : unixNow() - WEEK; + }, [ev]); + const { badges, awards } = useBadges(host, started); const mutedPubkeys = useMemo(() => { return new Set(getTagValues(login?.muted.tags ?? [], "p")); }, [login]); diff --git a/src/hooks/badges.ts b/src/hooks/badges.ts index 48ab2fd..ed8b162 100644 --- a/src/hooks/badges.ts +++ b/src/hooks/badges.ts @@ -7,18 +7,16 @@ import { RequestBuilder, } from "@snort/system"; import { useRequestBuilder } from "@snort/system-react"; -import { unixNow } from "@snort/shared"; import { findTag, toAddress, getTagValues } from "utils"; -import { WEEK } from "const"; import { System } from "index"; import type { Badge } from "types"; export function useBadges( pubkey: string, + since: number, leaveOpen = true ): { badges: Badge[]; awards: TaggedRawEvent[] } { - const since = useMemo(() => unixNow() - WEEK, [pubkey]); const rb = useMemo(() => { const rb = new RequestBuilder(`badges:${pubkey.slice(0, 12)}`); rb.withOptions({ leaveOpen }); diff --git a/src/hooks/live-streams.ts b/src/hooks/live-streams.ts index d4a6277..5a1322a 100644 --- a/src/hooks/live-streams.ts +++ b/src/hooks/live-streams.ts @@ -42,17 +42,19 @@ export function useStreamsFeed(tag?: string) { return []; }, [feed.data]); - const live = feedSorted.filter( - (a) => findTag(a, "status") === StreamState.Live - ).sort(sortStarts); - const planned = feedSorted.filter( - (a) => findTag(a, "status") === StreamState.Planned - ).sort(sortStarts); - const ended = feedSorted.filter((a) => { - const hasEnded = findTag(a, "status") === StreamState.Ended; - const recording = findTag(a, "recording") ?? ""; - return hasEnded && recording?.length > 0; - }).sort(sortCreatedAt); + const live = feedSorted + .filter((a) => findTag(a, "status") === StreamState.Live) + .sort(sortStarts); + const planned = feedSorted + .filter((a) => findTag(a, "status") === StreamState.Planned) + .sort(sortStarts); + const ended = feedSorted + .filter((a) => { + const hasEnded = findTag(a, "status") === StreamState.Ended; + const recording = findTag(a, "recording") ?? ""; + return hasEnded && recording?.length > 0; + }) + .sort(sortCreatedAt); return { live, planned, ended }; }