Long form thread fixes
This commit is contained in:
parent
5182b65591
commit
4a2aa2aced
@ -2,9 +2,9 @@ import "./Thread.css";
|
|||||||
import { useMemo, useState, ReactNode, useContext } from "react";
|
import { useMemo, useState, ReactNode, useContext } from "react";
|
||||||
import { useIntl } from "react-intl";
|
import { useIntl } from "react-intl";
|
||||||
import { useNavigate, useParams } from "react-router-dom";
|
import { useNavigate, useParams } from "react-router-dom";
|
||||||
import { TaggedNostrEvent, u256, NostrPrefix, EventExt, parseNostrLink } from "@snort/system";
|
import { TaggedNostrEvent, u256, NostrPrefix, EventExt, parseNostrLink, NostrLink } from "@snort/system";
|
||||||
|
|
||||||
import { getReactions, getAllReactions } from "SnortUtils";
|
import { getReactions, getAllReactions, unwrap } from "SnortUtils";
|
||||||
import BackButton from "Element/BackButton";
|
import BackButton from "Element/BackButton";
|
||||||
import Note from "Element/Note";
|
import Note from "Element/Note";
|
||||||
import NoteGhost from "Element/NoteGhost";
|
import NoteGhost from "Element/NoteGhost";
|
||||||
@ -154,9 +154,8 @@ const TierThree = ({ active, isLastSubthread, notes, related, chains, onNavigate
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
className={`subthread-container ${hasMultipleNotes ? "subthread-multi" : ""} ${
|
className={`subthread-container ${hasMultipleNotes ? "subthread-multi" : ""} ${isLast ? "subthread-last" : "subthread-mid"
|
||||||
isLast ? "subthread-last" : "subthread-mid"
|
}`}>
|
||||||
}`}>
|
|
||||||
<Divider variant="small" />
|
<Divider variant="small" />
|
||||||
<Note
|
<Note
|
||||||
highlight={active === first.id}
|
highlight={active === first.id}
|
||||||
@ -185,9 +184,8 @@ const TierThree = ({ active, isLastSubthread, notes, related, chains, onNavigate
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={r.id}
|
key={r.id}
|
||||||
className={`subthread-container ${lastReply ? "" : "subthread-multi"} ${
|
className={`subthread-container ${lastReply ? "" : "subthread-multi"} ${lastReply ? "subthread-last" : "subthread-mid"
|
||||||
lastReply ? "subthread-last" : "subthread-mid"
|
}`}>
|
||||||
}`}>
|
|
||||||
<Divider variant="small" />
|
<Divider variant="small" />
|
||||||
<Note
|
<Note
|
||||||
className={`thread-note ${lastNote ? "is-last-note" : ""}`}
|
className={`thread-note ${lastNote ? "is-last-note" : ""}`}
|
||||||
@ -297,6 +295,11 @@ export function Thread(props: { onBack?: () => void }) {
|
|||||||
description: "Navigate back button on threads view",
|
description: "Navigate back button on threads view",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const rootChainId = (ev: TaggedNostrEvent) => {
|
||||||
|
const link = NostrLink.fromEvent(ev);
|
||||||
|
return unwrap(link.toEventTag())[1];
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="main-content p">
|
<div className="main-content p">
|
||||||
@ -304,7 +307,7 @@ export function Thread(props: { onBack?: () => void }) {
|
|||||||
</div>
|
</div>
|
||||||
<div className="main-content">
|
<div className="main-content">
|
||||||
{thread.root && renderRoot(thread.root)}
|
{thread.root && renderRoot(thread.root)}
|
||||||
{thread.root && renderChain(thread.root.id)}
|
{thread.root && renderChain(rootChainId(thread.root))}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
@ -10,15 +10,13 @@ export function useReactions(subId: string, ids: Array<NostrLink>, others?: (rb:
|
|||||||
const rb = new RequestBuilder(subId);
|
const rb = new RequestBuilder(subId);
|
||||||
|
|
||||||
if (ids.length > 0) {
|
if (ids.length > 0) {
|
||||||
const f = rb
|
rb
|
||||||
.withFilter()
|
.withFilter()
|
||||||
.kinds(
|
.kinds(
|
||||||
pref.enableReactions
|
pref.enableReactions
|
||||||
? [EventKind.Reaction, EventKind.Repost, EventKind.ZapReceipt]
|
? [EventKind.Reaction, EventKind.Repost, EventKind.ZapReceipt]
|
||||||
: [EventKind.ZapReceipt, EventKind.Repost],
|
: [EventKind.ZapReceipt, EventKind.Repost],
|
||||||
);
|
).replyToLink(ids);
|
||||||
|
|
||||||
ids.forEach(v => f.replyToLink(v));
|
|
||||||
}
|
}
|
||||||
others?.(rb);
|
others?.(rb);
|
||||||
return rb.numFilters > 0 ? rb : null;
|
return rb.numFilters > 0 ? rb : null;
|
||||||
|
@ -13,10 +13,7 @@ export default function useThreadFeed(link: NostrLink) {
|
|||||||
leaveOpen: true,
|
leaveOpen: true,
|
||||||
});
|
});
|
||||||
sub.withFilter().link(link);
|
sub.withFilter().link(link);
|
||||||
sub.withFilter().kinds([EventKind.TextNote]).replyToLink(link);
|
sub.withFilter().kinds([EventKind.TextNote]).replyToLink([link, ...allEvents]);
|
||||||
allEvents.forEach(x => {
|
|
||||||
sub.withFilter().kinds([EventKind.TextNote]).replyToLink(x);
|
|
||||||
});
|
|
||||||
return sub;
|
return sub;
|
||||||
}, [allEvents.length]);
|
}, [allEvents.length]);
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ export default function useZapsFeed(link?: NostrLink) {
|
|||||||
const sub = useMemo(() => {
|
const sub = useMemo(() => {
|
||||||
if (!link) return null;
|
if (!link) return null;
|
||||||
const b = new RequestBuilder(`zaps:${link.encode()}`);
|
const b = new RequestBuilder(`zaps:${link.encode()}`);
|
||||||
b.withFilter().kinds([EventKind.ZapReceipt]).replyToLink(link);
|
b.withFilter().kinds([EventKind.ZapReceipt]).replyToLink([link]);
|
||||||
return b;
|
return b;
|
||||||
}, [link]);
|
}, [link]);
|
||||||
|
|
||||||
|
@ -15,6 +15,13 @@ export interface ThreadContext {
|
|||||||
|
|
||||||
export const ThreadContext = createContext({} as ThreadContext);
|
export const ThreadContext = createContext({} as ThreadContext);
|
||||||
|
|
||||||
|
export function threadChainKey(ev: TaggedNostrEvent) {
|
||||||
|
const t = EventExt.extractThread(ev);
|
||||||
|
if (t) {
|
||||||
|
return unwrap(t.replyTo?.value ?? t.root?.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function ThreadContextWrapper({ link, children }: { link: NostrLink; children?: ReactNode }) {
|
export function ThreadContextWrapper({ link, children }: { link: NostrLink; children?: ReactNode }) {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const [currentId, setCurrentId] = useState(link.id);
|
const [currentId, setCurrentId] = useState(link.id);
|
||||||
@ -26,21 +33,12 @@ export function ThreadContextWrapper({ link, children }: { link: NostrLink; chil
|
|||||||
feed.thread
|
feed.thread
|
||||||
?.sort((a, b) => b.created_at - a.created_at)
|
?.sort((a, b) => b.created_at - a.created_at)
|
||||||
.forEach(v => {
|
.forEach(v => {
|
||||||
const t = EventExt.extractThread(v);
|
const replyTo = threadChainKey(v);
|
||||||
if (t) {
|
if (replyTo) {
|
||||||
let replyTo = t.replyTo?.value ?? t.root?.value;
|
if (!chains.has(replyTo)) {
|
||||||
if (t.root?.key === "a" && t.root?.value) {
|
chains.set(replyTo, [v]);
|
||||||
const parsed = t.root.value.split(":");
|
} else {
|
||||||
replyTo = feed.thread?.find(
|
unwrap(chains.get(replyTo)).push(v);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -38,6 +38,7 @@ import { preload, RelayMetrics, UserCache, UserRelays } from "Cache";
|
|||||||
import { LoginStore } from "Login";
|
import { LoginStore } from "Login";
|
||||||
import { SnortDeckLayout } from "Pages/DeckLayout";
|
import { SnortDeckLayout } from "Pages/DeckLayout";
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
const WasmQueryOptimizer = {
|
const WasmQueryOptimizer = {
|
||||||
expandFilter: (f: ReqFilter) => {
|
expandFilter: (f: ReqFilter) => {
|
||||||
return expand_filter(f) as Array<FlatReqFilter>;
|
return expand_filter(f) as Array<FlatReqFilter>;
|
||||||
@ -60,7 +61,7 @@ export const System = new NostrSystem({
|
|||||||
relayCache: UserRelays,
|
relayCache: UserRelays,
|
||||||
profileCache: UserCache,
|
profileCache: UserCache,
|
||||||
relayMetrics: RelayMetrics,
|
relayMetrics: RelayMetrics,
|
||||||
queryOptimizer: WasmQueryOptimizer,
|
//queryOptimizer: WasmQueryOptimizer,
|
||||||
authHandler: async (c, r) => {
|
authHandler: async (c, r) => {
|
||||||
const { id } = LoginStore.snapshot();
|
const { id } = LoginStore.snapshot();
|
||||||
const pub = LoginStore.getPublisher(id);
|
const pub = LoginStore.getPublisher(id);
|
||||||
|
@ -9,6 +9,7 @@ import {
|
|||||||
HexKey,
|
HexKey,
|
||||||
Lists,
|
Lists,
|
||||||
NostrEvent,
|
NostrEvent,
|
||||||
|
NostrLink,
|
||||||
NotSignedNostrEvent,
|
NotSignedNostrEvent,
|
||||||
PowMiner,
|
PowMiner,
|
||||||
PrivateKeySigner,
|
PrivateKeySigner,
|
||||||
@ -187,9 +188,9 @@ export class EventPublisher {
|
|||||||
if (thread) {
|
if (thread) {
|
||||||
const rootOrReplyAsRoot = thread.root || thread.replyTo;
|
const rootOrReplyAsRoot = thread.root || thread.replyTo;
|
||||||
if (rootOrReplyAsRoot) {
|
if (rootOrReplyAsRoot) {
|
||||||
eb.tag(["e", rootOrReplyAsRoot?.value ?? "", rootOrReplyAsRoot?.relay ?? "", "root"]);
|
eb.tag([rootOrReplyAsRoot.key, rootOrReplyAsRoot.value ?? "", rootOrReplyAsRoot.relay ?? "", "root"]);
|
||||||
}
|
}
|
||||||
eb.tag(["e", replyTo.id, replyTo.relays?.[0] ?? "", "reply"]);
|
eb.tag([...(NostrLink.fromEvent(replyTo).toEventTag() ?? []), "reply"]);
|
||||||
|
|
||||||
eb.tag(["p", replyTo.pubkey]);
|
eb.tag(["p", replyTo.pubkey]);
|
||||||
for (const pk of thread.pubKeys) {
|
for (const pk of thread.pubKeys) {
|
||||||
@ -199,7 +200,7 @@ export class EventPublisher {
|
|||||||
eb.tag(["p", pk]);
|
eb.tag(["p", pk]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
eb.tag(["e", replyTo.id, "", "reply"]);
|
eb.tag([...(NostrLink.fromEvent(replyTo).toEventTag() ?? []), "reply"]);
|
||||||
// dont tag self in replies
|
// dont tag self in replies
|
||||||
if (replyTo.pubkey !== this.#pubKey) {
|
if (replyTo.pubkey !== this.#pubKey) {
|
||||||
eb.tag(["p", replyTo.pubkey]);
|
eb.tag(["p", replyTo.pubkey]);
|
||||||
|
@ -250,16 +250,27 @@ export class RequestFilterBuilder {
|
|||||||
/**
|
/**
|
||||||
* Get replies to link with e/a tags
|
* Get replies to link with e/a tags
|
||||||
*/
|
*/
|
||||||
replyToLink(link: NostrLink) {
|
replyToLink(links: Array<NostrLink>) {
|
||||||
if (link.type === NostrPrefix.Address) {
|
const grouped = links.reduce((acc, v) => {
|
||||||
this.tag("a", [`${link.kind}:${link.author}:${link.id}`]);
|
acc[v.type] ??= [];
|
||||||
link.relays?.forEach(v => this.relay(v));
|
if (v.type === NostrPrefix.Address) {
|
||||||
} else if (link.type === NostrPrefix.PublicKey || link.type === NostrPrefix.Profile) {
|
acc[v.type].push(`${v.kind}:${v.author}:${v.id}`);
|
||||||
this.tag("p", [link.id]);
|
} else if (v.type === NostrPrefix.PublicKey || v.type === NostrPrefix.Profile) {
|
||||||
link.relays?.forEach(v => this.relay(v));
|
acc[v.type].push(v.id);
|
||||||
} else {
|
} else {
|
||||||
this.tag("e", [link.id]);
|
acc[v.type].push(v.id);
|
||||||
link.relays?.forEach(v => this.relay(v));
|
}
|
||||||
|
return acc;
|
||||||
|
}, {} as Record<string, Array<string>>);
|
||||||
|
|
||||||
|
for(const [k,v] of Object.entries(grouped)) {
|
||||||
|
if (k === NostrPrefix.Address) {
|
||||||
|
this.tag("a", v);
|
||||||
|
} else if (k === NostrPrefix.PublicKey || k === NostrPrefix.Profile) {
|
||||||
|
this.tag("p", v);
|
||||||
|
} else {
|
||||||
|
this.tag("e", v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -293,7 +304,7 @@ export class RequestFilterBuilder {
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
filters: [this.filter],
|
filters: [this.#filter],
|
||||||
relay: "",
|
relay: "",
|
||||||
strategy: RequestStrategy.DefaultRelays,
|
strategy: RequestStrategy.DefaultRelays,
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user