improve mastodon note conversion and use access checks in more places (resolves #509)

This commit is contained in:
Hazelnoot 2025-01-31 12:54:18 -05:00
parent 3550ce27d5
commit 1e43162ba7
8 changed files with 222 additions and 236 deletions

View file

@ -4,7 +4,8 @@
*/
import { parseTimelineArgs, TimelineArgs } from '@/server/api/mastodon/timelineArgs.js';
import { convertNotification } from '../converters.js';
import { MiLocalUser } from '@/models/User.js';
import { MastoConverters } from '@/server/api/mastodon/converters.js';
import type { MegalodonInterface } from 'megalodon';
import type { FastifyRequest } from 'fastify';
@ -19,23 +20,25 @@ export class ApiNotifyMastodon {
constructor(
private readonly request: FastifyRequest<ApiNotifyMastodonRoute>,
private readonly client: MegalodonInterface,
private readonly me: MiLocalUser | null,
private readonly mastoConverters: MastoConverters,
) {}
public async getNotifications() {
const data = await this.client.getNotifications(parseTimelineArgs(this.request.query));
return data.data.map(n => {
const converted = convertNotification(n);
return Promise.all(data.data.map(async n => {
const converted = await this.mastoConverters.convertNotification(n, this.me);
if (converted.type === 'reaction') {
converted.type = 'favourite';
}
return converted;
});
}));
}
public async getNotification() {
if (!this.request.params.id) throw new Error('Missing required parameter "id"');
const data = await this.client.getNotification(this.request.params.id);
const converted = convertNotification(data.data);
const converted = await this.mastoConverters.convertNotification(data.data, this.me);
if (converted.type === 'reaction') {
converted.type = 'favourite';
}