forked from Kieran/snort
Always load thread info
This commit is contained in:
parent
7831bdbcc2
commit
9e162f0014
@ -58,13 +58,12 @@ export default function Note(props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function replyTag() {
|
function replyTag() {
|
||||||
let thread = ev.GetThread();
|
if (ev.Thread === null) {
|
||||||
if (thread === null) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let replyId = thread?.ReplyTo?.Event;
|
let replyId = ev.Thread?.ReplyTo?.Event;
|
||||||
let mentions = thread?.PubKeys?.map(a => [a, users[a]])?.map(a => a[1]?.name ?? a[0].substring(0, 8));
|
let mentions = ev.Thread?.PubKeys?.map(a => [a, users[a]])?.map(a => a[1]?.name ?? a[0].substring(0, 8));
|
||||||
return (
|
return (
|
||||||
<div className="reply" onClick={(e) => goToEvent(e, replyId)}>
|
<div className="reply" onClick={(e) => goToEvent(e, replyId)}>
|
||||||
➡️ {mentions?.join(", ") ?? replyId?.substring(0, 8)}
|
➡️ {mentions?.join(", ") ?? replyId?.substring(0, 8)}
|
||||||
|
@ -13,13 +13,12 @@ export default function Thread(props) {
|
|||||||
const notes = props.notes?.map(a => Event.FromObject(a));
|
const notes = props.notes?.map(a => Event.FromObject(a));
|
||||||
|
|
||||||
// root note has no thread info
|
// 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(() => {
|
const chains = useMemo(() => {
|
||||||
let chains = new Map();
|
let chains = new Map();
|
||||||
notes.filter(a => a.Kind === EventKind.TextNote).sort((a, b) => b.CreatedAt - a.CreatedAt).forEach((v) => {
|
notes.filter(a => a.Kind === EventKind.TextNote).sort((a, b) => b.CreatedAt - a.CreatedAt).forEach((v) => {
|
||||||
let thread = v.GetThread();
|
let replyTo = v.Thread?.ReplyTo?.Event ?? v.Thread?.Root?.Event;
|
||||||
let replyTo = thread?.ReplyTo?.Event ?? thread?.Root?.Event;
|
|
||||||
if (replyTo) {
|
if (replyTo) {
|
||||||
if (!chains.has(replyTo)) {
|
if (!chains.has(replyTo)) {
|
||||||
chains.set(replyTo, [v]);
|
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));
|
return Array.from(chains?.keys()).filter(a => !notes.some(b => b.Id === a));
|
||||||
}, [chains]);
|
}, [chains]);
|
||||||
|
|
||||||
|
const mentionsRoot = useMemo(() => {
|
||||||
|
return notes.filter(a => a.Kind === EventKind.TextNote && a.Thread)
|
||||||
|
}, [chains]);
|
||||||
|
|
||||||
function reactions(id, kind = EventKind.Reaction) {
|
function reactions(id, kind = EventKind.Reaction) {
|
||||||
return notes?.filter(a => a.Kind === kind && a.Tags.find(a => a.Key === "e" && a.Event === id));
|
return notes?.filter(a => a.Kind === kind && a.Tags.find(a => a.Key === "e" && a.Event === id));
|
||||||
}
|
}
|
||||||
|
@ -62,12 +62,12 @@ export default function useEventPublisher() {
|
|||||||
ev.Kind = EventKind.TextNote;
|
ev.Kind = EventKind.TextNote;
|
||||||
ev.Content = msg;
|
ev.Content = msg;
|
||||||
|
|
||||||
let thread = replyTo.GetThread();
|
let thread = replyTo.Thread;
|
||||||
if (thread) {
|
if (thread) {
|
||||||
if (thread.Root) {
|
if (thread.Root) {
|
||||||
ev.Tags.push(new Tag(["e", thread.Root.Event, "", "root"], ev.Tags.length));
|
ev.Tags.push(new Tag(["e", thread.Root.Event, "", "root"], ev.Tags.length));
|
||||||
} else {
|
} else {
|
||||||
let unRootedReply = thread.Reply.GetThread();
|
let unRootedReply = thread.Reply.Thread;
|
||||||
ev.Tags.push(new Tag(["e", unRootedReply.ReplyTo.Event, "", "root"], ev.Tags.length));
|
ev.Tags.push(new Tag(["e", unRootedReply.ReplyTo.Event, "", "root"], ev.Tags.length));
|
||||||
}
|
}
|
||||||
if (thread.Reply) {
|
if (thread.Reply) {
|
||||||
|
@ -51,6 +51,12 @@ export default class Event {
|
|||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
this.Signature = null;
|
this.Signature = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thread information for this event
|
||||||
|
* @type {Thread}
|
||||||
|
*/
|
||||||
|
this.Thread = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -97,14 +103,6 @@ export default class Event {
|
|||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get thread information
|
|
||||||
* @returns {Thread}
|
|
||||||
*/
|
|
||||||
GetThread() {
|
|
||||||
return Thread.ExtractThread(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does this event have content
|
* Does this event have content
|
||||||
* @returns {boolean}
|
* @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.Tags = obj.tags.map((e, i) => new Tag(e, i)).filter(a => !a.Invalid);
|
||||||
ret.Content = obj.content;
|
ret.Content = obj.content;
|
||||||
ret.Signature = obj.sig;
|
ret.Signature = obj.sig;
|
||||||
|
ret.Thread = Thread.ExtractThread(ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,8 +20,7 @@ export default function NotificationsPage() {
|
|||||||
return notifications?.filter(a => a.kind === EventKind.Reaction)
|
return notifications?.filter(a => a.kind === EventKind.Reaction)
|
||||||
.map(a => {
|
.map(a => {
|
||||||
let ev = Event.FromObject(a);
|
let ev = Event.FromObject(a);
|
||||||
let thread = ev.GetThread();
|
return ev.Thread?.ReplyTo?.Event ?? ev.Thread?.Root?.Event;
|
||||||
return thread?.ReplyTo?.Event ?? thread?.Root?.Event;
|
|
||||||
})
|
})
|
||||||
}, [notifications]);
|
}, [notifications]);
|
||||||
|
|
||||||
@ -54,8 +53,7 @@ export default function NotificationsPage() {
|
|||||||
return <Note data={a} key={a.id} reactions={reactions} />
|
return <Note data={a} key={a.id} reactions={reactions} />
|
||||||
} else if (a.kind === EventKind.Reaction) {
|
} else if (a.kind === EventKind.Reaction) {
|
||||||
let ev = Event.FromObject(a);
|
let ev = Event.FromObject(a);
|
||||||
let thread = ev.GetThread();
|
let reactedTo = ev.Thread?.ReplyTo?.Event ?? ev.Thread?.Root?.Event;
|
||||||
let reactedTo = thread?.ReplyTo?.Event ?? thread?.Root?.Event;
|
|
||||||
let reactedNote = otherNotes?.notes?.find(c => c.id === reactedTo);
|
let reactedNote = otherNotes?.notes?.find(c => c.id === reactedTo);
|
||||||
return <NoteReaction data={a} key={a.id} root={reactedNote} />
|
return <NoteReaction data={a} key={a.id} root={reactedNote} />
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user