Always load thread info

This commit is contained in:
Kieran 2023-01-06 19:29:12 +00:00
parent 7831bdbcc2
commit 9e162f0014
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
5 changed files with 20 additions and 21 deletions

View File

@ -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 (
<div className="reply" onClick={(e) => goToEvent(e, replyId)}>
{mentions?.join(", ") ?? replyId?.substring(0, 8)}

View File

@ -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));
}

View File

@ -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) {

View File

@ -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;
}

View File

@ -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 <Note data={a} key={a.id} reactions={reactions} />
} 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 <NoteReaction data={a} key={a.id} root={reactedNote} />
}