Adjust zap goals & chat zaps
This commit is contained in:
@ -66,7 +66,7 @@ export function LiveChat({
|
|||||||
height?: number;
|
height?: number;
|
||||||
}) {
|
}) {
|
||||||
const host = getHost(ev);
|
const host = getHost(ev);
|
||||||
const feed = useLiveChatFeed(link, host);
|
const feed = useLiveChatFeed(link, goal ? [goal.id] : undefined);
|
||||||
const login = useLogin();
|
const login = useLogin();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const pubkeys = [
|
const pubkeys = [
|
||||||
@ -81,7 +81,7 @@ export function LiveChat({
|
|||||||
.filter((z) => z && z.valid);
|
.filter((z) => z && z.valid);
|
||||||
|
|
||||||
const goalZaps = feed.zaps
|
const goalZaps = feed.zaps
|
||||||
.filter((ev) => (goal ? ev.created_at > goal.created_at : false))
|
.filter((ev) => (goal ? ev.created_at > goal.created_at && ev.tags.some(t => t[0] === "e" && t[1] === goal.id) : false))
|
||||||
.map((ev) => parseZap(ev, System.ProfileLoader.Cache))
|
.map((ev) => parseZap(ev, System.ProfileLoader.Cache))
|
||||||
.filter((z) => z && z.valid);
|
.filter((z) => z && z.valid);
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ export function LiveChat({
|
|||||||
<div className="top-zappers-container">
|
<div className="top-zappers-container">
|
||||||
<TopZappers zaps={zaps} />
|
<TopZappers zaps={zaps} />
|
||||||
</div>
|
</div>
|
||||||
{goal && <Goal link={link} ev={goal} zaps={goalZaps} /> }
|
{goal && <Goal link={link} ev={goal} zaps={goalZaps} />}
|
||||||
{login?.pubkey === streamer && <NewGoalDialog link={link} />}
|
{login?.pubkey === streamer && <NewGoalDialog link={link} />}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
@ -5,24 +5,26 @@ import {
|
|||||||
FlatNoteStore,
|
FlatNoteStore,
|
||||||
} from "@snort/system";
|
} from "@snort/system";
|
||||||
import { useRequestBuilder } from "@snort/system-react";
|
import { useRequestBuilder } from "@snort/system-react";
|
||||||
|
import { unixNow } from "@snort/shared";
|
||||||
import { System } from "index";
|
import { System } from "index";
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import { LIVE_STREAM_CHAT } from "const";
|
import { LIVE_STREAM_CHAT } from "const";
|
||||||
|
|
||||||
export function useLiveChatFeed(link: NostrLink, host?: string) {
|
export function useLiveChatFeed(link: NostrLink, eZaps?: Array<string>) {
|
||||||
const sub = useMemo(() => {
|
const sub = useMemo(() => {
|
||||||
const rb = new RequestBuilder(`live:${link.id}:${link.author}`);
|
const rb = new RequestBuilder(`live:${link.id}:${link.author}`);
|
||||||
rb.withOptions({
|
rb.withOptions({
|
||||||
leaveOpen: true,
|
leaveOpen: true,
|
||||||
});
|
});
|
||||||
|
const zapsSince = unixNow() - (60 * 60 * 24 * 7); // 7-days of zaps
|
||||||
const aTag = `${link.kind}:${link.author}:${link.id}`;
|
const aTag = `${link.kind}:${link.author}:${link.id}`;
|
||||||
rb.withFilter().kinds([LIVE_STREAM_CHAT]).tag("a", [aTag]).limit(100);
|
rb.withFilter().kinds([LIVE_STREAM_CHAT]).tag("a", [aTag]).limit(100);
|
||||||
rb.withFilter().kinds([EventKind.ZapReceipt]).tag("a", [aTag]);
|
rb.withFilter().kinds([EventKind.ZapReceipt]).tag("a", [aTag]).since(zapsSince);
|
||||||
if (host) {
|
if (eZaps) {
|
||||||
rb.withFilter().kinds([EventKind.ZapReceipt]).tag("p", [host]);
|
rb.withFilter().kinds([EventKind.ZapReceipt]).tag("e", eZaps);
|
||||||
}
|
}
|
||||||
return rb;
|
return rb;
|
||||||
}, [link, host]);
|
}, [link, eZaps]);
|
||||||
|
|
||||||
const feed = useRequestBuilder<FlatNoteStore>(System, FlatNoteStore, sub);
|
const feed = useRequestBuilder<FlatNoteStore>(System, FlatNoteStore, sub);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user