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]);
return (
<div>
<video ref={video} controls={true} autoPlay={true} muted={true} />
<div className="w-max">
<video className="w-max" ref={video} controls={true} />
</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
const root = useMemo(() => {
const currentNote =
thread.data?.find(ne => ne.id === currentId) ??
(location.state && "sig" in location.state ? (location.state as TaggedRawEvent) : undefined);
thread.data?.find(
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) {
const currentThread = EventExt.extractThread(currentNote);
const isRoot = (ne?: ThreadInfo) => ne === undefined;

View File

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

View File

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

View File

@ -204,7 +204,7 @@ export class RequestFilterBuilder {
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;
this.#filter[`#${key}`] = appendDedupe(this.#filter[`#${key}`], value);
return this;