fix: only show awards from stream start #77
@ -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]);
|
||||
|
@ -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 });
|
||||
|
@ -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 };
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user