Skip to content

Commit

Permalink
[Issue-3515] feat: mark read, unread, allread
Browse files Browse the repository at this point in the history
  • Loading branch information
bluezdot committed Sep 28, 2024
1 parent b44e2ed commit 8be3399
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ export class InappNotificationService implements CronServiceInterface {
this.notificationSetting.timePeriod = notificationTimePeriod;
}

async markAllRead (address: string) {
await this.dbService.markAllRead(address);
}

async markRead (address: string, notification: NotificationInfo) {
await this.dbService.markRead(address, notification);
}

async markUnread (address: string, notification: NotificationInfo) {
await this.dbService.markUnread(address, notification);
}

async getWithdrawNotifications () {
const NOTIFICATION_TRANSACTION_TYPE = NotificationTransactionType.WITHDRAW;
const allWithdrawNotifications: NotificationInfo[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,18 @@ export default class DatabaseService {
return this.stores.inappNotification.bulkUpsert(notifications);
}

public markAllRead (address: string) {
return this.stores.inappNotification.markAllRead(address);
}

public markRead (address: string, notification: NotificationInfo) {
return this.stores.inappNotification.markRead(address, notification);
}

public markUnread (address: string, notification: NotificationInfo) {
return this.stores.inappNotification.markUnread(address, notification);
}

async exportDB () {
const blob = await exportDB(this._db, {
filter: (table, value, key) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,28 @@ export default class InappNotificationStore extends BaseStore<NotificationInfo>
getAllUnreadNotifications () {
return this.table.filter((item) => !item.isRead).count();
}

markAllRead (address: string) {
return this.table.where('address')
.equalsIgnoreCase(address)
.modify({isRead: true});
}

markRead (address: string, notification: NotificationInfo) {
const id = notification.id;

return this.table.where('address')
.equalsIgnoreCase(address)
.and((notification) => notification.id === id)
.modify({isRead: true});
}

markUnread (address: string, notification: NotificationInfo) {
const id = notification.id;

return this.table.where('address')
.equalsIgnoreCase(address)
.and((notification) => notification.id === id)
.modify({isRead: false})
}
}

0 comments on commit 8be3399

Please sign in to comment.