diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2025-03-27 20:30:04 -0400 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2025-03-27 20:30:04 -0400 |
| commit | 848a07a170322ec18cfcd6b6dd4c1e372656737f (patch) | |
| tree | 5e10e603508dcc7887c351ebb8dd4ea33d7e8af1 /packages/backend/src/server/api | |
| parent | use exclusive ranges in api/i/notifications and /api/v1/notifications (diff) | |
| download | sharkey-848a07a170322ec18cfcd6b6dd4c1e372656737f.tar.gz sharkey-848a07a170322ec18cfcd6b6dd4c1e372656737f.tar.bz2 sharkey-848a07a170322ec18cfcd6b6dd4c1e372656737f.zip | |
Ignore notifications that reference missing notes
Diffstat (limited to 'packages/backend/src/server/api')
3 files changed, 22 insertions, 3 deletions
diff --git a/packages/backend/src/server/api/mastodon/MastodonConverters.ts b/packages/backend/src/server/api/mastodon/MastodonConverters.ts index 0e8ce5a2a7..e5d732ed79 100644 --- a/packages/backend/src/server/api/mastodon/MastodonConverters.ts +++ b/packages/backend/src/server/api/mastodon/MastodonConverters.ts @@ -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 { account: await this.convertAccount(notification.account), created_at: notification.created_at, id: notification.id, - status: notification.status ? await this.convertStatus(notification.status, me) : undefined, + status, type: convertNotificationType(notification.type as NotificationType), }; } diff --git a/packages/backend/src/server/api/mastodon/MastodonLogger.ts b/packages/backend/src/server/api/mastodon/MastodonLogger.ts index 57cf876dff..81d3e8f03d 100644 --- a/packages/backend/src/server/api/mastodon/MastodonLogger.ts +++ b/packages/backend/src/server/api/mastodon/MastodonLogger.ts @@ -35,7 +35,7 @@ export class MastodonLogger { // TODO move elsewhere export interface MastodonError { error: string; - error_description: string; + error_description?: string; } export function getErrorData(error: unknown): MastodonError { diff --git a/packages/backend/src/server/api/mastodon/endpoints/notifications.ts b/packages/backend/src/server/api/mastodon/endpoints/notifications.ts index c81b3ca236..c3108c8b3e 100644 --- a/packages/backend/src/server/api/mastodon/endpoints/notifications.ts +++ b/packages/backend/src/server/api/mastodon/endpoints/notifications.ts @@ -32,6 +32,9 @@ export class ApiNotificationsMastodon { const notifications = await Promise.all(data.data.map(n => this.mastoConverters.convertNotification(n, me))); const response: MastodonEntity.Notification[] = []; for (const notification of notifications) { + // Notifications for inaccessible notes will be null and should be ignored + if (!notification) continue; + response.push(notification); if (notification.type === 'reaction') { response.push({ @@ -52,6 +55,13 @@ export class ApiNotificationsMastodon { const data = await client.getNotification(_request.params.id); 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); }); |