Long form thread fixes

This commit is contained in:
2023-09-22 13:18:14 +01:00
parent 5182b65591
commit 4a2aa2aced
8 changed files with 57 additions and 48 deletions

View File

@ -9,6 +9,7 @@ import {
HexKey,
Lists,
NostrEvent,
NostrLink,
NotSignedNostrEvent,
PowMiner,
PrivateKeySigner,
@ -187,9 +188,9 @@ export class EventPublisher {
if (thread) {
const rootOrReplyAsRoot = thread.root || thread.replyTo;
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]);
for (const pk of thread.pubKeys) {
@ -199,7 +200,7 @@ export class EventPublisher {
eb.tag(["p", pk]);
}
} else {
eb.tag(["e", replyTo.id, "", "reply"]);
eb.tag([...(NostrLink.fromEvent(replyTo).toEventTag() ?? []), "reply"]);
// dont tag self in replies
if (replyTo.pubkey !== this.#pubKey) {
eb.tag(["p", replyTo.pubkey]);

View File

@ -250,16 +250,27 @@ export class RequestFilterBuilder {
/**
* Get replies to link with e/a tags
*/
replyToLink(link: NostrLink) {
if (link.type === NostrPrefix.Address) {
this.tag("a", [`${link.kind}:${link.author}:${link.id}`]);
link.relays?.forEach(v => this.relay(v));
} else if (link.type === NostrPrefix.PublicKey || link.type === NostrPrefix.Profile) {
this.tag("p", [link.id]);
link.relays?.forEach(v => this.relay(v));
} else {
this.tag("e", [link.id]);
link.relays?.forEach(v => this.relay(v));
replyToLink(links: Array<NostrLink>) {
const grouped = links.reduce((acc, v) => {
acc[v.type] ??= [];
if (v.type === NostrPrefix.Address) {
acc[v.type].push(`${v.kind}:${v.author}:${v.id}`);
} else if (v.type === NostrPrefix.PublicKey || v.type === NostrPrefix.Profile) {
acc[v.type].push(v.id);
} else {
acc[v.type].push(v.id);
}
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;
}
@ -293,7 +304,7 @@ export class RequestFilterBuilder {
return [
{
filters: [this.filter],
filters: [this.#filter],
relay: "",
strategy: RequestStrategy.DefaultRelays,
},