Ignore notifications that reference missing notes

This commit is contained in:
Hazelnoot 2025-03-27 20:30:04 -04:00
parent a92416904f
commit 848a07a170
3 changed files with 22 additions and 3 deletions

View file

@ -351,12 +351,21 @@ export class MastodonConverters {
}; };
} }
public async convertNotification(notification: Entity.Notification, me: MiLocalUser | null): Promise<MastodonEntity.Notification> { public async convertNotification(notification: Entity.Notification, me: MiLocalUser | null): Promise<MastodonEntity.Notification | null> {
const status = notification.status
? await this.convertStatus(notification.status, me).catch(() => null)
: null;
// We sometimes get notifications for inaccessible notes, these should be ignored.
if (!status) {
return null;
}
return { return {
account: await this.convertAccount(notification.account), account: await this.convertAccount(notification.account),
created_at: notification.created_at, created_at: notification.created_at,
id: notification.id, id: notification.id,
status: notification.status ? await this.convertStatus(notification.status, me) : undefined, status,
type: convertNotificationType(notification.type as NotificationType), type: convertNotificationType(notification.type as NotificationType),
}; };
} }

View file

@ -35,7 +35,7 @@ export class MastodonLogger {
// TODO move elsewhere // TODO move elsewhere
export interface MastodonError { export interface MastodonError {
error: string; error: string;
error_description: string; error_description?: string;
} }
export function getErrorData(error: unknown): MastodonError { export function getErrorData(error: unknown): MastodonError {

View file

@ -32,6 +32,9 @@ export class ApiNotificationsMastodon {
const notifications = await Promise.all(data.data.map(n => this.mastoConverters.convertNotification(n, me))); const notifications = await Promise.all(data.data.map(n => this.mastoConverters.convertNotification(n, me)));
const response: MastodonEntity.Notification[] = []; const response: MastodonEntity.Notification[] = [];
for (const notification of notifications) { for (const notification of notifications) {
// Notifications for inaccessible notes will be null and should be ignored
if (!notification) continue;
response.push(notification); response.push(notification);
if (notification.type === 'reaction') { if (notification.type === 'reaction') {
response.push({ response.push({
@ -52,6 +55,13 @@ export class ApiNotificationsMastodon {
const data = await client.getNotification(_request.params.id); const data = await client.getNotification(_request.params.id);
const response = await this.mastoConverters.convertNotification(data.data, me); const response = await this.mastoConverters.convertNotification(data.data, me);
// Notifications for inaccessible notes will be null and should be ignored
if (!response) {
return reply.code(404).send({
error: 'NOT_FOUND',
});
}
reply.send(response); reply.send(response);
}); });