Skip to content

Commit

Permalink
firefish getStatusContext: add ancestors by calling notes/conversation
Browse files Browse the repository at this point in the history
- getStatusContext should return ancestors but firefish does not return them with notes/chilren.
- notes/conversation does provide ancestors but It requires another call.
- calling different api twice can be controversy about dealing options - duplicating results, but better than no ancestors at all imo.
  • Loading branch information
sftblw committed Nov 1, 2024
1 parent e2298ae commit 353277b
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions megalodon/src/firefish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1146,36 +1146,50 @@ export default class Firefish implements MegalodonInterface {
id: string,
options?: { limit?: number; max_id?: string; since_id?: string }
): Promise<Response<Entity.Context>> {
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<Array<FirefishAPI.Entity.Note>>('/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<Array<FirefishAPI.Entity.Note>>('/api/notes/children', paramsAncestors);
let descendantsRes = await this.client.post<Array<FirefishAPI.Entity.Note>>('/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<Response<Entity.StatusSource>> {
Expand Down

0 comments on commit 353277b

Please sign in to comment.