Adjust zap goals & chat zaps

This commit is contained in:
Kieran 2023-07-13 13:29:31 +01:00
parent 21c8d5c158
commit 7ae4cf5221
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
2 changed files with 10 additions and 8 deletions

View File

@ -66,7 +66,7 @@ export function LiveChat({
height?: number;
}) {
const host = getHost(ev);
const feed = useLiveChatFeed(link, host);
const feed = useLiveChatFeed(link, goal ? [goal.id] : undefined);
const login = useLogin();
useEffect(() => {
const pubkeys = [
@ -81,7 +81,7 @@ export function LiveChat({
.filter((z) => z && z.valid);
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))
.filter((z) => z && z.valid);
@ -124,7 +124,7 @@ export function LiveChat({
<div className="top-zappers-container">
<TopZappers zaps={zaps} />
</div>
{goal && <Goal link={link} ev={goal} zaps={goalZaps} /> }
{goal && <Goal link={link} ev={goal} zaps={goalZaps} />}
{login?.pubkey === streamer && <NewGoalDialog link={link} />}
</div>
)}

View File

@ -5,24 +5,26 @@ import {
FlatNoteStore,
} from "@snort/system";
import { useRequestBuilder } from "@snort/system-react";
import { unixNow } from "@snort/shared";
import { System } from "index";
import { useMemo } from "react";
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 rb = new RequestBuilder(`live:${link.id}:${link.author}`);
rb.withOptions({
leaveOpen: true,
});
const zapsSince = unixNow() - (60 * 60 * 24 * 7); // 7-days of zaps
const aTag = `${link.kind}:${link.author}:${link.id}`;
rb.withFilter().kinds([LIVE_STREAM_CHAT]).tag("a", [aTag]).limit(100);
rb.withFilter().kinds([EventKind.ZapReceipt]).tag("a", [aTag]);
if (host) {
rb.withFilter().kinds([EventKind.ZapReceipt]).tag("p", [host]);
rb.withFilter().kinds([EventKind.ZapReceipt]).tag("a", [aTag]).since(zapsSince);
if (eZaps) {
rb.withFilter().kinds([EventKind.ZapReceipt]).tag("e", eZaps);
}
return rb;
}, [link, host]);
}, [link, eZaps]);
const feed = useRequestBuilder<FlatNoteStore>(System, FlatNoteStore, sub);