refactor: use noteNotificationTypes

This commit is contained in:
Johann150 2022-06-21 09:52:49 +02:00
parent 35fd970c4a
commit 58aa7d36aa
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1

View file

@ -1,4 +1,5 @@
import { In } from 'typeorm'; import { In } from 'typeorm';
import { noteNotificationTypes } from 'foundkey-js';
import { db } from '@/db/postgre.js'; import { db } from '@/db/postgre.js';
import { aggregateNoteEmojis, prefetchEmojis } from '@/misc/populate-emojis.js'; import { aggregateNoteEmojis, prefetchEmojis } from '@/misc/populate-emojis.js';
import { Packed } from '@/misc/schema.js'; import { Packed } from '@/misc/schema.js';
@ -28,50 +29,18 @@ export const NotificationRepository = db.getRepository(Notification).extend({
isRead: notification.isRead, isRead: notification.isRead,
userId: notification.notifierId, userId: notification.notifierId,
user: notification.notifierId ? Users.pack(notification.notifier || notification.notifierId) : null, user: notification.notifierId ? Users.pack(notification.notifier || notification.notifierId) : null,
...(notification.type === 'mention' ? { ...(noteNotificationTypes.includes(notification.type) ? {
note: Notes.pack(notification.note || notification.noteId!, { id: notification.notifieeId }, {
detail: true,
_hint_: options._hintForEachNotes_,
}),
} : {}),
...(notification.type === 'reply' ? {
note: Notes.pack(notification.note || notification.noteId!, { id: notification.notifieeId }, {
detail: true,
_hint_: options._hintForEachNotes_,
}),
} : {}),
...(notification.type === 'renote' ? {
note: Notes.pack(notification.note || notification.noteId!, { id: notification.notifieeId }, {
detail: true,
_hint_: options._hintForEachNotes_,
}),
} : {}),
...(notification.type === 'quote' ? {
note: Notes.pack(notification.note || notification.noteId!, { id: notification.notifieeId }, { note: Notes.pack(notification.note || notification.noteId!, { id: notification.notifieeId }, {
detail: true, detail: true,
_hint_: options._hintForEachNotes_, _hint_: options._hintForEachNotes_,
}), }),
} : {}), } : {}),
...(notification.type === 'reaction' ? { ...(notification.type === 'reaction' ? {
note: Notes.pack(notification.note || notification.noteId!, { id: notification.notifieeId }, {
detail: true,
_hint_: options._hintForEachNotes_,
}),
reaction: notification.reaction, reaction: notification.reaction,
} : {}), } : {}),
...(notification.type === 'pollVote' ? { ...(notification.type === 'pollVote' ? {
note: Notes.pack(notification.note || notification.noteId!, { id: notification.notifieeId }, {
detail: true,
_hint_: options._hintForEachNotes_,
}),
choice: notification.choice, choice: notification.choice,
} : {}), } : {}),
...(notification.type === 'pollEnded' ? {
note: Notes.pack(notification.note || notification.noteId!, { id: notification.notifieeId }, {
detail: true,
_hint_: options._hintForEachNotes_,
}),
} : {}),
...(notification.type === 'groupInvited' ? { ...(notification.type === 'groupInvited' ? {
invitation: UserGroupInvitations.pack(notification.userGroupInvitationId!), invitation: UserGroupInvitations.pack(notification.userGroupInvitationId!),
} : {}), } : {}),