diff --git a/megalodon/src/firefish.ts b/megalodon/src/firefish.ts index efb729a0..d83d3a43 100644 --- a/megalodon/src/firefish.ts +++ b/megalodon/src/firefish.ts @@ -1146,36 +1146,50 @@ export default class Firefish implements MegalodonInterface { id: string, options?: { limit?: number; max_id?: string; since_id?: string } ): Promise> { - let params = { + let paramsDescendants = { noteId: id } if (options) { if (options.limit) { - params = Object.assign(params, { + paramsDescendants = Object.assign(paramsDescendants, { limit: options.limit }) } if (options.max_id) { - params = Object.assign(params, { + paramsDescendants = Object.assign(paramsDescendants, { untilId: options.max_id }) } if (options.since_id) { - params = Object.assign(params, { + paramsDescendants = Object.assign(paramsDescendants, { sinceId: options.since_id }) } } - return this.client.post>('/api/notes/children', params).then(res => { - const context: Entity.Context = { - ancestors: [], - descendants: res.data.map(n => FirefishAPI.Converter.note(n)) - } - return { - ...res, - data: context + + let paramsAncestors = { + noteId: id + } + if (options) { + if (options.limit) { + paramsAncestors = Object.assign(paramsDescendants, { + limit: options.limit + }) } - }) + } + + let ancestorsPromise = this.client.post>('/api/notes/children', paramsAncestors); + let descendantsRes = await this.client.post>('/api/notes/conversation', paramsDescendants); + + const context: Entity.Context = { + ancestors: (await ancestorsPromise).data.map(n => FirefishAPI.Converter.note(n)).reverse(), + descendants: descendantsRes.data.map(n => FirefishAPI.Converter.note(n)) + }; + + return { + ...descendantsRes, + data: context + } } public async getStatusSource(_id: string): Promise> {