diff --git a/src/element/Note.js b/src/element/Note.js
index 64df27b6..a25fe045 100644
--- a/src/element/Note.js
+++ b/src/element/Note.js
@@ -58,13 +58,12 @@ export default function Note(props) {
}
function replyTag() {
- let thread = ev.GetThread();
- if (thread === null) {
+ if (ev.Thread === null) {
return null;
}
- let replyId = thread?.ReplyTo?.Event;
- let mentions = thread?.PubKeys?.map(a => [a, users[a]])?.map(a => a[1]?.name ?? a[0].substring(0, 8));
+ let replyId = ev.Thread?.ReplyTo?.Event;
+ let mentions = ev.Thread?.PubKeys?.map(a => [a, users[a]])?.map(a => a[1]?.name ?? a[0].substring(0, 8));
return (
goToEvent(e, replyId)}>
➡️ {mentions?.join(", ") ?? replyId?.substring(0, 8)}
diff --git a/src/element/Thread.js b/src/element/Thread.js
index 62137228..0a8a9380 100644
--- a/src/element/Thread.js
+++ b/src/element/Thread.js
@@ -13,13 +13,12 @@ export default function Thread(props) {
const notes = props.notes?.map(a => Event.FromObject(a));
// root note has no thread info
- const root = useMemo(() => notes.find(a => a.GetThread() === null), [notes]);
+ const root = useMemo(() => notes.find(a => a.Thread === null), [notes]);
const chains = useMemo(() => {
let chains = new Map();
notes.filter(a => a.Kind === EventKind.TextNote).sort((a, b) => b.CreatedAt - a.CreatedAt).forEach((v) => {
- let thread = v.GetThread();
- let replyTo = thread?.ReplyTo?.Event ?? thread?.Root?.Event;
+ let replyTo = v.Thread?.ReplyTo?.Event ?? v.Thread?.Root?.Event;
if (replyTo) {
if (!chains.has(replyTo)) {
chains.set(replyTo, [v]);
@@ -38,6 +37,10 @@ export default function Thread(props) {
return Array.from(chains?.keys()).filter(a => !notes.some(b => b.Id === a));
}, [chains]);
+ const mentionsRoot = useMemo(() => {
+ return notes.filter(a => a.Kind === EventKind.TextNote && a.Thread)
+ }, [chains]);
+
function reactions(id, kind = EventKind.Reaction) {
return notes?.filter(a => a.Kind === kind && a.Tags.find(a => a.Key === "e" && a.Event === id));
}
diff --git a/src/feed/EventPublisher.js b/src/feed/EventPublisher.js
index 288ca4b9..91daa2ac 100644
--- a/src/feed/EventPublisher.js
+++ b/src/feed/EventPublisher.js
@@ -62,12 +62,12 @@ export default function useEventPublisher() {
ev.Kind = EventKind.TextNote;
ev.Content = msg;
- let thread = replyTo.GetThread();
+ let thread = replyTo.Thread;
if (thread) {
if (thread.Root) {
ev.Tags.push(new Tag(["e", thread.Root.Event, "", "root"], ev.Tags.length));
} else {
- let unRootedReply = thread.Reply.GetThread();
+ let unRootedReply = thread.Reply.Thread;
ev.Tags.push(new Tag(["e", unRootedReply.ReplyTo.Event, "", "root"], ev.Tags.length));
}
if (thread.Reply) {
diff --git a/src/nostr/Event.js b/src/nostr/Event.js
index cc341dc4..dcad2503 100644
--- a/src/nostr/Event.js
+++ b/src/nostr/Event.js
@@ -51,6 +51,12 @@ export default class Event {
* @type {string}
*/
this.Signature = null;
+
+ /**
+ * Thread information for this event
+ * @type {Thread}
+ */
+ this.Thread = null;
}
/**
@@ -97,14 +103,6 @@ export default class Event {
return hash;
}
- /**
- * Get thread information
- * @returns {Thread}
- */
- GetThread() {
- return Thread.ExtractThread(this);
- }
-
/**
* Does this event have content
* @returns {boolean}
@@ -130,6 +128,7 @@ export default class Event {
ret.Tags = obj.tags.map((e, i) => new Tag(e, i)).filter(a => !a.Invalid);
ret.Content = obj.content;
ret.Signature = obj.sig;
+ ret.Thread = Thread.ExtractThread(ret);
return ret;
}
diff --git a/src/pages/Notifications.js b/src/pages/Notifications.js
index adb4221a..fdb1f1ef 100644
--- a/src/pages/Notifications.js
+++ b/src/pages/Notifications.js
@@ -20,8 +20,7 @@ export default function NotificationsPage() {
return notifications?.filter(a => a.kind === EventKind.Reaction)
.map(a => {
let ev = Event.FromObject(a);
- let thread = ev.GetThread();
- return thread?.ReplyTo?.Event ?? thread?.Root?.Event;
+ return ev.Thread?.ReplyTo?.Event ?? ev.Thread?.Root?.Event;
})
}, [notifications]);
@@ -54,8 +53,7 @@ export default function NotificationsPage() {
return
} else if (a.kind === EventKind.Reaction) {
let ev = Event.FromObject(a);
- let thread = ev.GetThread();
- let reactedTo = thread?.ReplyTo?.Event ?? thread?.Root?.Event;
+ let reactedTo = ev.Thread?.ReplyTo?.Event ?? ev.Thread?.Root?.Event;
let reactedNote = otherNotes?.notes?.find(c => c.id === reactedTo);
return
}