fix: find reply root properly
All checks were successful
create archive with lfs / tag (push) Successful in 9s
All checks were successful
create archive with lfs / tag (push) Successful in 9s
This commit is contained in:
parent
b2915e3087
commit
7440f6139e
@ -32,18 +32,19 @@ export const readNote = (id: NoteId): Note => {
|
|||||||
return JSON.parse(readFileSync(getNotePath(id)).toString())
|
return JSON.parse(readFileSync(getNotePath(id)).toString())
|
||||||
}
|
}
|
||||||
export const findReplyRoot = (id: NoteId): {rootNote: Note, rootNoteId: NoteId} => {
|
export const findReplyRoot = (id: NoteId): {rootNote: Note, rootNoteId: NoteId} => {
|
||||||
let currentNoteId: string | null = id
|
let noteId: string | null = id
|
||||||
let currentNote: Note | null = null
|
let current: {rootNote?: Note, rootNoteId?: NoteId} = {}
|
||||||
while (currentNoteId !== null) {
|
while (noteId !== null) {
|
||||||
currentNote = readNote(currentNoteId)
|
current.rootNote = readNote(noteId)
|
||||||
currentNoteId = currentNote.replyTo ?? null
|
current.rootNoteId = noteId
|
||||||
|
noteId = current.rootNote.replyTo ?? null
|
||||||
}
|
}
|
||||||
if (currentNote === null || currentNoteId === null) {
|
if (current.rootNote === undefined || current.rootNoteId === undefined) {
|
||||||
throw "no note with id found"
|
throw "no note with id found"
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
rootNote: currentNote,
|
rootNote: current.rootNote,
|
||||||
rootNoteId: currentNoteId,
|
rootNoteId: current.rootNoteId,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export const writeNote = (id: NoteId, note: Note) => {
|
export const writeNote = (id: NoteId, note: Note) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user