NotificationRepository
app/features/notifications/NotificationRepository.server.ts- Tables
- NotificationNotificationUserNotificationUserSubscriptionUser
- Calls
- no other repositories
- Imports
- no other modules
- Used by
- 1 loader3 routes4 routines2 scripts4 other
Functions & values
export function insert( notification: Notification, users: Array<Omit<TablesInsertable["NotificationUser"], "notificationId">>, )
export function findByUserId( userId: number, { limit }: { limit?: number } = {}, )
export function findAllByType<T extends Notification["type"]>(type: T)
Marks the users' unseen notifications of the type (optionally only those whose meta matches every key/value) as seen, returning the user ids whose rows changed. The correlated exists keeps this proportional to the users' own notifications; notificationId in (select ...) makes SQLite materialize every notification of the type first, ~80x slower on a hot path.
export async function markAsSeenByType({ userIds, type, meta, }: { userIds: number[]; type: Notification["type"]; meta?: Record<string, number | string>; }): Promise<number[]>
Unit tests (6)
export async function findUserIdsWithUnseenByType({ userIds, type, meta, }: { userIds: number[]; type: Notification["type"]; meta: Record<string, number | string>; }): Promise<number[]>
Marks the actor's notifications as seen. Returns [actorId] if any row changed, else [], shaped for ChatSystemMessage.notifyNotificationsChanged.
export async function markOwnAsSeen(notificationIds: number[])
Unit tests (4)
export function deleteOld()
Saves the actor's push subscription, keeping only their {@link NOTIFICATIONS.MAX_PUSH_SUBSCRIPTIONS_PER_USER} most recent ones.
export function upsertOwnSubscription(subscription: NotificationSubscription)
Unit tests (6)
Push subscriptions of the notification's recipients who have not seen it yet, so the push sender skips users who addressed it during the grace period.
export function findUnseenSubscriptionsByNotificationId( notificationId: number, )
Unit tests (4)
export function findAllSubscriptionsByUserIds(userIds: number[])
export function deleteSubscriptionById(id: number)