merge: handle "follow" notifs from deleted user (!1032)

View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/1032

Approved-by: Hazelnoot <acomputerdog@gmail.com>
Approved-by: Marie <github@yuugi.dev>
This commit is contained in:
Marie 2025-05-26 18:34:11 +00:00
commit 2ce8a9b9a7
2 changed files with 24 additions and 15 deletions

View file

@ -23,6 +23,13 @@ import type { NoteEntityService } from './NoteEntityService.js';
const NOTE_REQUIRED_NOTIFICATION_TYPES = new Set(['note', 'mention', 'reply', 'renote', 'renote:grouped', 'quote', 'reaction', 'reaction:grouped', 'pollEnded', 'edited', 'scheduledNotePosted'] as (typeof groupedNotificationTypes[number])[]); const NOTE_REQUIRED_NOTIFICATION_TYPES = new Set(['note', 'mention', 'reply', 'renote', 'renote:grouped', 'quote', 'reaction', 'reaction:grouped', 'pollEnded', 'edited', 'scheduledNotePosted'] as (typeof groupedNotificationTypes[number])[]);
function undefOnMissing<T>(packPromise: Promise<T>): Promise<T | undefined> {
return packPromise.catch(err => {
if (err instanceof EntityNotFoundError) return undefined;
throw err;
});
}
@Injectable() @Injectable()
export class NotificationEntityService implements OnModuleInit { export class NotificationEntityService implements OnModuleInit {
private userEntityService: UserEntityService; private userEntityService: UserEntityService;
@ -75,9 +82,9 @@ export class NotificationEntityService implements OnModuleInit {
const noteIfNeed = needsNote ? ( const noteIfNeed = needsNote ? (
hint?.packedNotes != null hint?.packedNotes != null
? hint.packedNotes.get(notification.noteId) ? hint.packedNotes.get(notification.noteId)
: this.noteEntityService.pack(notification.noteId, { id: meId }, { : undefOnMissing(this.noteEntityService.pack(notification.noteId, { id: meId }, {
detail: true, detail: true,
}) }))
) : undefined; ) : undefined;
// if the note has been deleted, don't show this notification // if the note has been deleted, don't show this notification
if (needsNote && !noteIfNeed) return null; if (needsNote && !noteIfNeed) return null;
@ -86,7 +93,7 @@ export class NotificationEntityService implements OnModuleInit {
const userIfNeed = needsUser ? ( const userIfNeed = needsUser ? (
hint?.packedUsers != null hint?.packedUsers != null
? hint.packedUsers.get(notification.notifierId) ? hint.packedUsers.get(notification.notifierId)
: this.userEntityService.pack(notification.notifierId, { id: meId }) : undefOnMissing(this.userEntityService.pack(notification.notifierId, { id: meId }))
) : undefined; ) : undefined;
// if the user has been deleted, don't show this notification // if the user has been deleted, don't show this notification
if (needsUser && !userIfNeed) return null; if (needsUser && !userIfNeed) return null;
@ -96,7 +103,7 @@ export class NotificationEntityService implements OnModuleInit {
const reactions = (await Promise.all(notification.reactions.map(async reaction => { const reactions = (await Promise.all(notification.reactions.map(async reaction => {
const user = hint?.packedUsers != null const user = hint?.packedUsers != null
? hint.packedUsers.get(reaction.userId)! ? hint.packedUsers.get(reaction.userId)!
: await this.userEntityService.pack(reaction.userId, { id: meId }); : await undefOnMissing(this.userEntityService.pack(reaction.userId, { id: meId }));
return { return {
user, user,
reaction: reaction.reaction, reaction: reaction.reaction,
@ -121,7 +128,7 @@ export class NotificationEntityService implements OnModuleInit {
return packedUser; return packedUser;
} }
return this.userEntityService.pack(userId, { id: meId }); return undefOnMissing(this.userEntityService.pack(userId, { id: meId }));
}))).filter(x => x != null); }))).filter(x => x != null);
// if all users have been deleted, don't show this notification // if all users have been deleted, don't show this notification
if (users.length === 0) { if (users.length === 0) {
@ -140,10 +147,7 @@ export class NotificationEntityService implements OnModuleInit {
const needsRole = notification.type === 'roleAssigned'; const needsRole = notification.type === 'roleAssigned';
const role = needsRole const role = needsRole
? await this.roleEntityService.pack(notification.roleId).catch(err => { ? await undefOnMissing(this.roleEntityService.pack(notification.roleId))
if (err instanceof EntityNotFoundError) return undefined;
throw err;
})
: undefined; : undefined;
// if the role has been deleted, don't show this notification // if the role has been deleted, don't show this notification
if (needsRole && !role) { if (needsRole && !role) {

View file

@ -242,13 +242,18 @@ watch(props, async () => {
const type = props.notification.type; const type = props.notification.type;
// To avoid extra lookups, only do the query when it actually matters. // To avoid extra lookups, only do the query when it actually matters.
if (type === 'follow' || type === 'receiveFollowRequest') { if ((type === 'follow' || type === 'receiveFollowRequest') && props.notification.userId) {
try {
const user = await misskeyApi('users/show', { const user = await misskeyApi('users/show', {
userId: props.notification.userId, userId: props.notification.userId,
}); });
userDetailed.value = user; userDetailed.value = user;
followRequestDone.value = !user.hasPendingFollowRequestToYou; followRequestDone.value = !user.hasPendingFollowRequestToYou;
} catch {
userDetailed.value = null;
followRequestDone.value = false;
}
} else { } else {
userDetailed.value = null; userDetailed.value = null;
followRequestDone.value = false; followRequestDone.value = false;