import type { BackendEvent } from '@wireapp/api-client/src/event' ; import type { Notification } from '@wireapp/api-client/src/notification/' ; import type { CRUDEngine } from '@wireapp/store-engine' ; import { CryptographyDatabaseRepository } from '../cryptography/CryptographyDatabaseRepository' ; export enum DatabaseStores { EVENTS = 'events' } export enum DatabaseKeys { PRIMARY_KEY_LAST_EVENT = 'z.storage.StorageKey.EVENT.LAST_DATE' , PRIMARY_KEY_LAST_NOTIFICATION = 'z.storage.StorageKey.NOTIFICATION.LAST_ID' } const STORE_AMPLIFY = CryptographyDatabaseRepository . STORES . AMPLIFY ; export class NotificationDatabaseRepository { constructor ( private readonly storeEngine ) { } public getNotificationEventList ( ) { return this . storeEngine . readAll < BackendEvent > ( DatabaseStores . EVENTS ) ; } public async getLastEventDate ( ) { const { value } = await this . storeEngine . read < { value : string ; } > ( STORE_AMPLIFY , DatabaseKeys . PRIMARY_KEY_LAST_EVENT ) ; return new Date ( value ) ; } public async updateLastEventDate ( eventDate ) { await this . storeEngine . update ( STORE_AMPLIFY , DatabaseKeys . PRIMARY_KEY_LAST_EVENT , { value : eventDate . toISOString ( ) } ) ; return eventDate ; } public async createLastEventDate ( eventDate ) { await this . storeEngine . create ( STORE_AMPLIFY , DatabaseKeys . PRIMARY_KEY_LAST_EVENT , { value : eventDate . toISOString ( ) } ) ; return eventDate ; } public async getLastNotificationId ( ) { const { value } = await this . storeEngine . read < { value : string ; } > ( STORE_AMPLIFY , DatabaseKeys . PRIMARY_KEY_LAST_NOTIFICATION ) ; return value ; } public async updateLastNotificationId ( lastNotification ) { await this . storeEngine . updateOrCreate ( STORE_AMPLIFY , DatabaseKeys . PRIMARY_KEY_LAST_NOTIFICATION , { value : lastNotification . id , } ) ; return lastNotification . id ; } }