mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2025-04-13 09:44:40 +00:00
Ignore notifications that reference missing notes
This commit is contained in:
parent
a92416904f
commit
848a07a170
3 changed files with 22 additions and 3 deletions
|
@ -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),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue