Cleanup
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
import "./Thread.css";
|
||||
import { useMemo, useState, ReactNode, useContext } from "react";
|
||||
import { useIntl } from "react-intl";
|
||||
import { useNavigate, Link, useParams } from "react-router-dom";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import { TaggedNostrEvent, u256, NostrPrefix, EventExt, parseNostrLink } from "@snort/system";
|
||||
|
||||
import { eventLink, getReactions, getAllReactions } from "SnortUtils";
|
||||
import { getReactions, getAllReactions } from "SnortUtils";
|
||||
import BackButton from "Element/BackButton";
|
||||
import Note from "Element/Note";
|
||||
import NoteGhost from "Element/NoteGhost";
|
||||
@ -154,9 +154,8 @@ const TierThree = ({ active, isLastSubthread, notes, related, chains, onNavigate
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
className={`subthread-container ${hasMultipleNotes ? "subthread-multi" : ""} ${
|
||||
isLast ? "subthread-last" : "subthread-mid"
|
||||
}`}>
|
||||
className={`subthread-container ${hasMultipleNotes ? "subthread-multi" : ""} ${isLast ? "subthread-last" : "subthread-mid"
|
||||
}`}>
|
||||
<Divider variant="small" />
|
||||
<Note
|
||||
highlight={active === first.id}
|
||||
@ -185,9 +184,8 @@ const TierThree = ({ active, isLastSubthread, notes, related, chains, onNavigate
|
||||
return (
|
||||
<div
|
||||
key={r.id}
|
||||
className={`subthread-container ${lastReply ? "" : "subthread-multi"} ${
|
||||
lastReply ? "subthread-last" : "subthread-mid"
|
||||
}`}>
|
||||
className={`subthread-container ${lastReply ? "" : "subthread-multi"} ${lastReply ? "subthread-last" : "subthread-mid"
|
||||
}`}>
|
||||
<Divider variant="small" />
|
||||
<Note
|
||||
className={`thread-note ${lastNote ? "is-last-note" : ""}`}
|
||||
@ -225,7 +223,7 @@ export function Thread(props: { onBack?: () => void }) {
|
||||
|
||||
function navigateThread(e: TaggedNostrEvent) {
|
||||
thread.setCurrent(e.id);
|
||||
//const link = encodeTLV(e.id, NostrPrefix.Event, e.relays);
|
||||
//router.navigate(`/e/${NostrLink.fromEvent(e).encode()}`, { replace: true })
|
||||
}
|
||||
|
||||
const parent = useMemo(() => {
|
||||
@ -239,8 +237,6 @@ export function Thread(props: { onBack?: () => void }) {
|
||||
}
|
||||
}, [thread.root]);
|
||||
|
||||
const brokenChains = Array.from(thread.chains?.keys()).filter(a => !thread.data?.some(b => b.id === a));
|
||||
|
||||
function renderRoot(note: TaggedNostrEvent) {
|
||||
const className = `thread-root${isSingleNote ? " thread-root-single" : ""}`;
|
||||
if (note) {
|
||||
@ -307,18 +303,6 @@ export function Thread(props: { onBack?: () => void }) {
|
||||
<div className="main-content">
|
||||
{thread.root && renderRoot(thread.root)}
|
||||
{thread.root && renderChain(thread.root.id)}
|
||||
|
||||
{brokenChains.length > 0 && <h3>Other replies</h3>}
|
||||
{brokenChains.map(a => {
|
||||
return (
|
||||
<div className="mb10">
|
||||
<NoteGhost className={`thread-note thread-root ghost-root`} key={a}>
|
||||
Missing event <Link to={eventLink(a)}>{a.substring(0, 8)}</Link>
|
||||
</NoteGhost>
|
||||
{renderChain(a)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
|
@ -1,29 +1,11 @@
|
||||
import { useMemo } from "react";
|
||||
import { NostrPrefix, RequestBuilder, ReplaceableNoteStore, NostrLink, NoteCollection } from "@snort/system";
|
||||
import { RequestBuilder, ReplaceableNoteStore, NostrLink, NoteCollection } from "@snort/system";
|
||||
import { useRequestBuilder } from "@snort/system-react";
|
||||
|
||||
import { unwrap } from "SnortUtils";
|
||||
|
||||
export function useEventFeed(link: NostrLink) {
|
||||
const sub = useMemo(() => {
|
||||
const b = new RequestBuilder(`event:${link.id.slice(0, 12)}`);
|
||||
if (link.type === NostrPrefix.Address) {
|
||||
const f = b.withFilter().tag("d", [link.id]);
|
||||
if (link.author) {
|
||||
f.authors([unwrap(link.author)]);
|
||||
}
|
||||
if (link.kind) {
|
||||
f.kinds([unwrap(link.kind)]);
|
||||
}
|
||||
} else {
|
||||
const f = b.withFilter().ids([link.id]);
|
||||
if (link.relays) {
|
||||
link.relays.slice(0, 2).forEach(r => f.relay(r));
|
||||
}
|
||||
if (link.author) {
|
||||
f.authors([link.author]);
|
||||
}
|
||||
}
|
||||
b.withFilter().link(link);
|
||||
return b;
|
||||
}, [link]);
|
||||
|
||||
@ -33,25 +15,7 @@ export function useEventFeed(link: NostrLink) {
|
||||
export function useEventsFeed(id: string, links: Array<NostrLink>) {
|
||||
const sub = useMemo(() => {
|
||||
const b = new RequestBuilder(`events:${id}`);
|
||||
for (const l of links) {
|
||||
if (l.type === NostrPrefix.Address) {
|
||||
const f = b.withFilter().tag("d", [l.id]);
|
||||
if (l.author) {
|
||||
f.authors([unwrap(l.author)]);
|
||||
}
|
||||
if (l.kind) {
|
||||
f.kinds([unwrap(l.kind)]);
|
||||
}
|
||||
} else {
|
||||
const f = b.withFilter().ids([l.id]);
|
||||
if (l.relays) {
|
||||
l.relays.slice(0, 2).forEach(r => f.relay(r));
|
||||
}
|
||||
if (l.author) {
|
||||
f.authors([l.author]);
|
||||
}
|
||||
}
|
||||
}
|
||||
links.forEach(v => b.withFilter().link(v));
|
||||
return b;
|
||||
}, [id, links]);
|
||||
|
||||
|
@ -1,19 +0,0 @@
|
||||
import { EventKind, FlatNoteStore, NostrLink, RequestBuilder } from "@snort/system";
|
||||
import { useRequestBuilder } from "@snort/system-react";
|
||||
import { useMemo } from "react";
|
||||
|
||||
export function useLiveChatFeed(link: NostrLink) {
|
||||
const sub = useMemo(() => {
|
||||
const rb = new RequestBuilder(`live:${link.id}:${link.author}`);
|
||||
rb.withOptions({
|
||||
leaveOpen: true,
|
||||
});
|
||||
rb.withFilter()
|
||||
.kinds([EventKind.ZapReceipt, 1311 as EventKind])
|
||||
.tag("a", [`${link.kind}:${link.author}:${link.id}`])
|
||||
.limit(100);
|
||||
return rb;
|
||||
}, [link]);
|
||||
|
||||
return useRequestBuilder(FlatNoteStore, sub);
|
||||
}
|
@ -2,25 +2,26 @@ import { useEffect, useMemo, useState } from "react";
|
||||
import { EventKind, NostrLink, RequestBuilder, NoteCollection } from "@snort/system";
|
||||
import { useRequestBuilder } from "@snort/system-react";
|
||||
|
||||
import useLogin from "Hooks/useLogin";
|
||||
import { useReactions } from "./FeedReactions";
|
||||
|
||||
export default function useThreadFeed(link: NostrLink) {
|
||||
const [allEvents, setAllEvents] = useState<Array<NostrLink>>([]);
|
||||
const pref = useLogin().preferences;
|
||||
|
||||
const sub = useMemo(() => {
|
||||
const sub = new RequestBuilder(`thread:${link.id}`);
|
||||
const sub = new RequestBuilder(`thread:${link.id.slice(0, 12)}`);
|
||||
sub.withOptions({
|
||||
leaveOpen: true,
|
||||
});
|
||||
sub.withFilter().kinds([EventKind.TextNote]).link(link);
|
||||
if (allEvents.length > 0) {
|
||||
const f = sub.withFilter().kinds([EventKind.TextNote]);
|
||||
allEvents.forEach(x => f.replyToLink(x));
|
||||
}
|
||||
sub
|
||||
.withFilter()
|
||||
.kinds([EventKind.TextNote])
|
||||
.link(link)
|
||||
.replyToLink(link);
|
||||
allEvents.forEach(x => {
|
||||
sub.withFilter().kinds([EventKind.TextNote]).link(x).replyToLink(x);
|
||||
});
|
||||
return sub;
|
||||
}, [allEvents.length, pref]);
|
||||
}, [allEvents.length]);
|
||||
|
||||
const store = useRequestBuilder(NoteCollection, sub);
|
||||
|
||||
@ -37,7 +38,7 @@ export default function useThreadFeed(link: NostrLink) {
|
||||
}
|
||||
}, [store.data?.length]);
|
||||
|
||||
const reactions = useReactions(`thread:${link.id}:reactions`, allEvents);
|
||||
const reactions = useReactions(`thread:${link.id.slice(0, 12)}:reactions`, allEvents);
|
||||
|
||||
return {
|
||||
thread: store.data ?? [],
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { useMemo } from "react";
|
||||
import { EventKind, RequestBuilder, parseZap, NostrLink, NostrPrefix, NoteCollection } from "@snort/system";
|
||||
import { EventKind, RequestBuilder, parseZap, NostrLink, NoteCollection } from "@snort/system";
|
||||
import { useRequestBuilder } from "@snort/system-react";
|
||||
import { UserCache } from "Cache";
|
||||
|
||||
@ -7,11 +7,7 @@ export default function useZapsFeed(link?: NostrLink) {
|
||||
const sub = useMemo(() => {
|
||||
if (!link) return null;
|
||||
const b = new RequestBuilder(`zaps:${link.encode()}`);
|
||||
if (link.type === NostrPrefix.PublicKey) {
|
||||
b.withFilter().tag("p", [link.id]).kinds([EventKind.ZapReceipt]);
|
||||
} else if (link.type === NostrPrefix.Event || link.type === NostrPrefix.Note) {
|
||||
b.withFilter().tag("e", [link.id]).kinds([EventKind.ZapReceipt]);
|
||||
}
|
||||
b.withFilter().kinds([EventKind.ZapReceipt]).replyToLink(link);
|
||||
return b;
|
||||
}, [link]);
|
||||
|
||||
|
@ -27,18 +27,20 @@ export function ThreadContextWrapper({ link, children }: { link: NostrLink; chil
|
||||
?.sort((a, b) => b.created_at - a.created_at)
|
||||
.forEach(v => {
|
||||
const t = EventExt.extractThread(v);
|
||||
let replyTo = t?.replyTo?.value ?? t?.root?.value;
|
||||
if (t?.root?.key === "a" && t?.root?.value) {
|
||||
const parsed = t.root.value.split(":");
|
||||
replyTo = feed.thread?.find(
|
||||
a => a.kind === Number(parsed[0]) && a.pubkey === parsed[1] && findTag(a, "d") === parsed[2],
|
||||
)?.id;
|
||||
}
|
||||
if (replyTo) {
|
||||
if (!chains.has(replyTo)) {
|
||||
chains.set(replyTo, [v]);
|
||||
} else {
|
||||
unwrap(chains.get(replyTo)).push(v);
|
||||
if (t) {
|
||||
let replyTo = t.replyTo?.value ?? t.root?.value;
|
||||
if (t.root?.key === "a" && t.root?.value) {
|
||||
const parsed = t.root.value.split(":");
|
||||
replyTo = feed.thread?.find(
|
||||
a => a.kind === Number(parsed[0]) && a.pubkey === parsed[1] && findTag(a, "d") === parsed[2],
|
||||
)?.id;
|
||||
}
|
||||
if (replyTo) {
|
||||
if (!chains.has(replyTo)) {
|
||||
chains.set(replyTo, [v]);
|
||||
} else {
|
||||
unwrap(chains.get(replyTo)).push(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -91,7 +93,7 @@ export function ThreadContextWrapper({ link, children }: { link: NostrLink; chil
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [feed.thread, currentId, location]);
|
||||
}, [feed.thread.length, currentId, location]);
|
||||
|
||||
const ctxValue = useMemo(() => {
|
||||
return {
|
||||
|
Reference in New Issue
Block a user