fix: only show awards from stream start

resolves #74
This commit is contained in:
verbiricha 2023-08-04 18:51:49 +02:00
parent 22a799aac7
commit 443b1b1738
3 changed files with 21 additions and 16 deletions

View File

@ -8,6 +8,7 @@ import {
parseZap, parseZap,
encodeTLV, encodeTLV,
} from "@snort/system"; } from "@snort/system";
import { unixNow } from "@snort/shared";
import { useEffect, useMemo } from "react"; import { useEffect, useMemo } from "react";
import uniqBy from "lodash.uniqby"; import uniqBy from "lodash.uniqby";
@ -28,7 +29,7 @@ import { useLogin } from "hooks/login";
import useTopZappers from "hooks/top-zappers"; import useTopZappers from "hooks/top-zappers";
import { useAddress } from "hooks/event"; import { useAddress } from "hooks/event";
import { formatSats } from "number"; import { formatSats } from "number";
import { LIVE_STREAM_CHAT } from "const"; import { WEEK, LIVE_STREAM_CHAT } from "const";
import { findTag, getTagValues, getHost } from "utils"; import { findTag, getTagValues, getHost } from "utils";
import { System } from "index"; import { System } from "index";
@ -91,7 +92,6 @@ export function LiveChat({
height?: number; height?: number;
}) { }) {
const host = getHost(ev); const host = getHost(ev);
const { badges, awards } = useBadges(host);
const feed = useLiveChatFeed(link, goal ? [goal.id] : undefined); const feed = useLiveChatFeed(link, goal ? [goal.id] : undefined);
const login = useLogin(); const login = useLogin();
useEffect(() => { useEffect(() => {
@ -101,6 +101,11 @@ export function LiveChat({
System.ProfileLoader.TrackMetadata(pubkeys); System.ProfileLoader.TrackMetadata(pubkeys);
return () => System.ProfileLoader.UntrackMetadata(pubkeys); return () => System.ProfileLoader.UntrackMetadata(pubkeys);
}, [feed.zaps]); }, [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(() => { const mutedPubkeys = useMemo(() => {
return new Set(getTagValues(login?.muted.tags ?? [], "p")); return new Set(getTagValues(login?.muted.tags ?? [], "p"));
}, [login]); }, [login]);

View File

@ -7,18 +7,16 @@ import {
RequestBuilder, RequestBuilder,
} from "@snort/system"; } from "@snort/system";
import { useRequestBuilder } from "@snort/system-react"; import { useRequestBuilder } from "@snort/system-react";
import { unixNow } from "@snort/shared";
import { findTag, toAddress, getTagValues } from "utils"; import { findTag, toAddress, getTagValues } from "utils";
import { WEEK } from "const";
import { System } from "index"; import { System } from "index";
import type { Badge } from "types"; import type { Badge } from "types";
export function useBadges( export function useBadges(
pubkey: string, pubkey: string,
since: number,
leaveOpen = true leaveOpen = true
): { badges: Badge[]; awards: TaggedRawEvent[] } { ): { badges: Badge[]; awards: TaggedRawEvent[] } {
const since = useMemo(() => unixNow() - WEEK, [pubkey]);
const rb = useMemo(() => { const rb = useMemo(() => {
const rb = new RequestBuilder(`badges:${pubkey.slice(0, 12)}`); const rb = new RequestBuilder(`badges:${pubkey.slice(0, 12)}`);
rb.withOptions({ leaveOpen }); rb.withOptions({ leaveOpen });

View File

@ -42,17 +42,19 @@ export function useStreamsFeed(tag?: string) {
return []; return [];
}, [feed.data]); }, [feed.data]);
const live = feedSorted.filter( const live = feedSorted
(a) => findTag(a, "status") === StreamState.Live .filter((a) => findTag(a, "status") === StreamState.Live)
).sort(sortStarts); .sort(sortStarts);
const planned = feedSorted.filter( const planned = feedSorted
(a) => findTag(a, "status") === StreamState.Planned .filter((a) => findTag(a, "status") === StreamState.Planned)
).sort(sortStarts); .sort(sortStarts);
const ended = feedSorted.filter((a) => { const ended = feedSorted
const hasEnded = findTag(a, "status") === StreamState.Ended; .filter((a) => {
const recording = findTag(a, "recording") ?? ""; const hasEnded = findTag(a, "status") === StreamState.Ended;
return hasEnded && recording?.length > 0; const recording = findTag(a, "recording") ?? "";
}).sort(sortCreatedAt); return hasEnded && recording?.length > 0;
})
.sort(sortCreatedAt);
return { live, planned, ended }; return { live, planned, ended };
} }