fix naddr loading

This commit is contained in:
Kieran 2023-06-17 22:07:17 +01:00
parent fa823afa33
commit 206aaca7b4
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
5 changed files with 42 additions and 30 deletions

View File

@ -14,8 +14,8 @@ export function LiveEvent({ ev }: { ev: NostrEvent }) {
} }
}, [video, ev]); }, [video, ev]);
return ( return (
<div> <div className="w-max">
<video ref={video} controls={true} autoPlay={true} muted={true} /> <video className="w-max" ref={video} controls={true} />
</div> </div>
); );
} }

View File

@ -261,8 +261,11 @@ export default function Thread() {
// Root is the parent of the current note or the current note if its a root note or the root of the thread // Root is the parent of the current note or the current note if its a root note or the root of the thread
const root = useMemo(() => { const root = useMemo(() => {
const currentNote = const currentNote =
thread.data?.find(ne => ne.id === currentId) ?? thread.data?.find(
(location.state && "sig" in location.state ? (location.state as TaggedRawEvent) : undefined); ne =>
ne.id === currentId ||
(link.type === NostrPrefix.Address && findTag(ne, "d") === currentId && ne.pubkey === link.author)
) ?? (location.state && "sig" in location.state ? (location.state as TaggedRawEvent) : undefined);
if (currentNote) { if (currentNote) {
const currentThread = EventExt.extractThread(currentNote); const currentThread = EventExt.extractThread(currentNote);
const isRoot = (ne?: ThreadInfo) => ne === undefined; const isRoot = (ne?: ThreadInfo) => ne === undefined;

View File

@ -1,5 +1,5 @@
import { useEffect, useMemo, useState } from "react"; import { useEffect, useMemo, useState } from "react";
import { u256, EventKind, NostrLink, FlatNoteStore, RequestBuilder } from "@snort/system"; import { u256, EventKind, NostrLink, FlatNoteStore, RequestBuilder, NostrPrefix } from "@snort/system";
import { useRequestBuilder } from "@snort/system-react"; import { useRequestBuilder } from "@snort/system-react";
import { appendDedupe } from "SnortUtils"; import { appendDedupe } from "SnortUtils";
@ -11,13 +11,9 @@ interface RelayTaggedEventId {
relay?: string; relay?: string;
} }
export default function useThreadFeed(link: NostrLink) { export default function useThreadFeed(link: NostrLink) {
const linkTagged = { const [trackingEvents, setTrackingEvent] = useState<Array<RelayTaggedEventId>>([]);
id: link.id,
relay: link.relays?.[0],
};
const [trackingEvents, setTrackingEvent] = useState<Array<RelayTaggedEventId>>([linkTagged]);
const [trackingATags, setTrackingATags] = useState<string[]>([]); const [trackingATags, setTrackingATags] = useState<string[]>([]);
const [allEvents, setAllEvents] = useState<Array<RelayTaggedEventId>>([linkTagged]); const [allEvents, setAllEvents] = useState<Array<RelayTaggedEventId>>([]);
const pref = useLogin().preferences; const pref = useLogin().preferences;
const sub = useMemo(() => { const sub = useMemo(() => {
@ -25,22 +21,25 @@ export default function useThreadFeed(link: NostrLink) {
sub.withOptions({ sub.withOptions({
leaveOpen: true, leaveOpen: true,
}); });
const fTracking = sub.withFilter(); if (trackingEvents.length > 0) {
for (const te of trackingEvents) { const fTracking = sub.withFilter();
fTracking.id(te.id, te.relay); for (const te of trackingEvents) {
fTracking.id(te.id, te.relay);
}
}
if (allEvents.length > 0) {
sub
.withFilter()
.kinds(
pref.enableReactions
? [EventKind.Reaction, EventKind.TextNote, EventKind.Repost, EventKind.ZapReceipt]
: [EventKind.TextNote, EventKind.ZapReceipt, EventKind.Repost]
)
.tag(
"e",
allEvents.map(a => a.id)
);
} }
sub
.withFilter()
.kinds(
pref.enableReactions
? [EventKind.Reaction, EventKind.TextNote, EventKind.Repost, EventKind.ZapReceipt]
: [EventKind.TextNote, EventKind.ZapReceipt, EventKind.Repost]
)
.tag(
"e",
allEvents.map(a => a.id)
);
if (trackingATags.length > 0) { if (trackingATags.length > 0) {
const parsed = trackingATags.map(a => a.split(":")); const parsed = trackingATags.map(a => a.split(":"));
sub sub
@ -51,6 +50,7 @@ export default function useThreadFeed(link: NostrLink) {
"d", "d",
parsed.map(a => a[2]) parsed.map(a => a[2])
); );
sub.withFilter().tag("a", trackingATags);
} }
return sub; return sub;
}, [trackingEvents, trackingATags, allEvents, pref]); }, [trackingEvents, trackingATags, allEvents, pref]);
@ -58,9 +58,17 @@ export default function useThreadFeed(link: NostrLink) {
const store = useRequestBuilder<FlatNoteStore>(System, FlatNoteStore, sub); const store = useRequestBuilder<FlatNoteStore>(System, FlatNoteStore, sub);
useEffect(() => { useEffect(() => {
setTrackingATags([]); if (link.type === NostrPrefix.Address) {
setTrackingEvent([linkTagged]); setTrackingATags([`${link.kind}:${link.author}:${link.id}`]);
setAllEvents([linkTagged]); } else {
setTrackingEvent([
{
id: link.id,
relay: link.relays?.[0],
},
]);
}
setAllEvents([]);
}, [link.id]); }, [link.id]);
useEffect(() => { useEffect(() => {

View File

@ -46,6 +46,7 @@ export interface ReqFilter {
"#t"?: string[]; "#t"?: string[];
"#d"?: string[]; "#d"?: string[];
"#r"?: string[]; "#r"?: string[];
"#a"?: string[];
search?: string; search?: string;
since?: number; since?: number;
until?: number; until?: number;

View File

@ -204,7 +204,7 @@ export class RequestFilterBuilder {
return this; return this;
} }
tag(key: "e" | "p" | "d" | "t" | "r", value?: Array<string>) { tag(key: "e" | "p" | "d" | "t" | "r" | "a", value?: Array<string>) {
if (!value) return this; if (!value) return this;
this.#filter[`#${key}`] = appendDedupe(this.#filter[`#${key}`], value); this.#filter[`#${key}`] = appendDedupe(this.#filter[`#${key}`], value);
return this; return this;