fix: short links
This commit is contained in:
@ -4,9 +4,10 @@ import { unixNow } from "@snort/shared";
|
|||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import { LIVE_STREAM_CHAT, WEEK } from "const";
|
import { LIVE_STREAM_CHAT, WEEK } from "const";
|
||||||
|
|
||||||
export function useLiveChatFeed(link: NostrLink, eZaps?: Array<string>, limit = 100) {
|
export function useLiveChatFeed(link?: NostrLink, eZaps?: Array<string>, limit = 100) {
|
||||||
const since = useMemo(() => unixNow() - WEEK, [link.id]);
|
const since = useMemo(() => unixNow() - WEEK, [link?.id]);
|
||||||
const sub = useMemo(() => {
|
const sub = useMemo(() => {
|
||||||
|
if (!link) return null;
|
||||||
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,
|
||||||
@ -14,7 +15,7 @@ export function useLiveChatFeed(link: NostrLink, eZaps?: Array<string>, limit =
|
|||||||
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(limit);
|
rb.withFilter().kinds([LIVE_STREAM_CHAT]).tag("a", [aTag]).limit(limit);
|
||||||
return rb;
|
return rb;
|
||||||
}, [link.id, since, eZaps]);
|
}, [link?.id, since, eZaps]);
|
||||||
|
|
||||||
const feed = useRequestBuilder(NoteCollection, sub);
|
const feed = useRequestBuilder(NoteCollection, sub);
|
||||||
|
|
||||||
@ -23,8 +24,8 @@ export function useLiveChatFeed(link: NostrLink, eZaps?: Array<string>, limit =
|
|||||||
}, [feed.data]);
|
}, [feed.data]);
|
||||||
|
|
||||||
const reactions = useReactions(
|
const reactions = useReactions(
|
||||||
`live:${link.id}:${link.author}:reactions`,
|
`live:${link?.id}:${link?.author}:reactions`,
|
||||||
messages.map(a => NostrLink.fromEvent(a)).concat(link),
|
messages.map(a => NostrLink.fromEvent(a)).concat(link ? [link] : []),
|
||||||
undefined,
|
undefined,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { fetchNip05Pubkey, hexToBech32 } from "@snort/shared";
|
import { fetchNip05Pubkey } from "@snort/shared";
|
||||||
import { NostrLink, tryParseNostrLink, NostrPrefix } from "@snort/system";
|
import { NostrLink, tryParseNostrLink, NostrPrefix } from "@snort/system";
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
@ -16,11 +16,7 @@ export function useStreamLink() {
|
|||||||
const [handle, domain] = (params.id.includes("@") ? params.id : `${params.id}@zap.stream`).split("@");
|
const [handle, domain] = (params.id.includes("@") ? params.id : `${params.id}@zap.stream`).split("@");
|
||||||
fetchNip05Pubkey(handle, domain).then(d => {
|
fetchNip05Pubkey(handle, domain).then(d => {
|
||||||
if (d) {
|
if (d) {
|
||||||
setLink({
|
setLink(new NostrLink(NostrPrefix.PublicKey, d));
|
||||||
id: d,
|
|
||||||
type: NostrPrefix.PublicKey,
|
|
||||||
encode: () => hexToBech32(NostrPrefix.PublicKey, d),
|
|
||||||
} as NostrLink);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,9 @@ interface StatSlot {
|
|||||||
|
|
||||||
export function StreamSummary({ link, preload }: { link: NostrLink; preload?: NostrEvent }) {
|
export function StreamSummary({ link, preload }: { link: NostrLink; preload?: NostrEvent }) {
|
||||||
const ev = useCurrentStreamFeed(link, true, preload);
|
const ev = useCurrentStreamFeed(link, true, preload);
|
||||||
const data = useLiveChatFeed(link, undefined, 5_000);
|
const thisLink = ev ? NostrLink.fromEvent(ev) : undefined;
|
||||||
const reactions = useEventReactions(link, data.reactions);
|
const data = useLiveChatFeed(thisLink, undefined, 5_000);
|
||||||
|
const reactions = useEventReactions(thisLink ?? link, data.reactions);
|
||||||
|
|
||||||
const chatSummary = useMemo(() => {
|
const chatSummary = useMemo(() => {
|
||||||
return Object.entries(
|
return Object.entries(
|
||||||
|
Reference in New Issue
Block a user