Better note ancestors lookup
This commit is contained in:
parent
8a11b1e152
commit
6973d24172
|
@ -1272,18 +1272,8 @@ export default class Misskey implements MegalodonInterface {
|
|||
return this.client.post<Array<MisskeyAPI.Entity.Note>>('/api/notes/children', params).then(async res => {
|
||||
console.log(JSON.stringify(res, null, 2));
|
||||
|
||||
const parents: Entity.Status[] = [];
|
||||
let lastNote = await this.getStatus(params.noteId);
|
||||
|
||||
for (let i = 0; i < 10; i++) {
|
||||
const parentId = this.getParent(lastNote.data);
|
||||
if (parentId == null)
|
||||
break;
|
||||
|
||||
const parent = await this.getStatus(parentId);
|
||||
parents.push(parent.data);
|
||||
lastNote = parent;
|
||||
}
|
||||
const conversation = await this.client.post<Array<MisskeyAPI.Entity.Note>>('/api/notes/conversation', params);
|
||||
const parents = await Promise.all(conversation.data.map(n => this.noteWithMentions(n, this.baseUrlToHost(this.baseUrl))));
|
||||
|
||||
const context: Entity.Context = {
|
||||
ancestors: parents.reverse(),
|
||||
|
@ -1296,10 +1286,6 @@ export default class Misskey implements MegalodonInterface {
|
|||
})
|
||||
}
|
||||
|
||||
private getParent(note: Entity.Status) {
|
||||
return note.in_reply_to_id ?? null;
|
||||
}
|
||||
|
||||
private dfs(graph: Entity.Status[]) {
|
||||
// we don't need to run dfs if we have zero or one elements
|
||||
if (graph.length <= 1) {
|
||||
|
|
Loading…
Reference in a new issue