[mastodon-client] implement favorited_by

This commit is contained in:
Laura Hausmann 2023-07-07 22:40:29 +02:00
parent c3f5836ac1
commit 2d47cdf53f
No known key found for this signature in database
GPG Key ID: D044E84C5BE01605
2 changed files with 22 additions and 6 deletions

View File

@ -197,7 +197,19 @@ export function apiStatusMastodon(router: Router): void {
router.get<{ Params: { id: string } }>(
"/v1/statuses/:id/favourited_by",
async (ctx) => {
ctx.body = [];
const BASE_URL = `${ctx.protocol}://${ctx.hostname}`;
const accessTokens = ctx.headers.authorization;
const client = getClient(BASE_URL, accessTokens);
try {
const data = await client.getStatusFavouritedBy(
convertId(ctx.params.id, IdType.CalckeyId),
);
ctx.body = data.data.map((account) => convertAccount(account));
} catch (e: any) {
console.error(e);
ctx.status = 401;
ctx.body = e.response.data;
}
},
);
router.post<{ Params: { id: string } }>(

View File

@ -1487,11 +1487,15 @@ export default class Misskey implements MegalodonInterface {
}))
}
public async getStatusFavouritedBy(_id: string): Promise<Response<Array<Entity.Account>>> {
return new Promise((_, reject) => {
const err = new NoImplementedError('misskey does not support')
reject(err)
})
public async getStatusFavouritedBy(id: string): Promise<Response<Array<Entity.Account>>> {
return this.client
.post<Array<MisskeyAPI.Entity.Reaction>>('/api/notes/reactions', {
noteId: id
})
.then(res => ({
...res,
data: res.data.map(n => this.converter.user(n.user))
}))
}
public async favouriteStatus(id: string): Promise<Response<Entity.Status>> {