From 294dddf511e8588fbea38629d841e62b77984076 Mon Sep 17 00:00:00 2001 From: Zeeshan Akram <37098720+zeeshanakram3@users.noreply.github.com> Date: Fri, 19 Jul 2024 18:34:06 +0500 Subject: [PATCH] fix: set notification.dispatch_block field for all type of notifications (#344) * fix: set notification.dispatch_block field for all type of notifications * address review comment * bump package version and update changelog --- CHANGELOG.md | 7 ++++++- package-lock.json | 4 ++-- package.json | 2 +- src/utils/notification/helpers.ts | 22 ++++++++++++---------- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87a9aa497..65c831704 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ -# 4.0.4 +# 4.0.6 + +## Bug Fixes: +- Fixed: Set `Notification.dispatchBlock` field for all type of notifications (both future and immediate), to allow querying notifications by block number at which they should be delivered - [#344](https://github.com/Joystream/orion/pull/344) + +# 4.0.5 ## Bug Fixes: - Fixed: avoiding IDs override/conflict while creating concurrent runtime notifications by reading/updating the `nextEntityId` from the `overlay` instead of DB - [#342](https://github.com/Joystream/orion/pull/342) diff --git a/package-lock.json b/package-lock.json index 9f82045bd..dc6c9b99a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "orion", - "version": "4.0.5", + "version": "4.0.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "orion", - "version": "4.0.5", + "version": "4.0.6", "hasInstallScript": true, "workspaces": [ "network-tests" diff --git a/package.json b/package.json index ef4247b79..bbc40125b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "orion", - "version": "4.0.5", + "version": "4.0.6", "engines": { "node": ">=16" }, diff --git a/src/utils/notification/helpers.ts b/src/utils/notification/helpers.ts index 9c112224d..738e901de 100644 --- a/src/utils/notification/helpers.ts +++ b/src/utils/notification/helpers.ts @@ -12,6 +12,7 @@ import { RecipientType, Unread, } from '../../model' +import { getCurrentBlockHeight } from '../blockHeight' import { uniqueId } from '../crypto' import { getNextIdForEntity } from '../nextEntityId' import { EntityManagerOverlay } from '../overlay' @@ -153,7 +154,7 @@ async function addOffChainNotification( account: Flat, recipient: RecipientType, notificationType: NotificationType, - dispatchBlock?: number + dispatchBlock: number ) { // get notification Id from orion_db in any case const nextNotificationId = await getNextIdForEntity(em, OFFCHAIN_NOTIFICATION_ID_TAG) @@ -163,8 +164,8 @@ async function addOffChainNotification( account.id, recipient, notificationType, - undefined, - dispatchBlock + dispatchBlock, + undefined ) const pref = preferencesForNotification(account.notificationPreferences, notificationType) @@ -184,7 +185,7 @@ async function addRuntimeNotification( recipient: RecipientType, notificationType: NotificationType, event: Event, - dispatchBlock?: number + dispatchBlock: number ) { // get notification Id from orion_db in any case const nextNotificationId = await getNextIdForEntity(overlay, RUNTIME_NOTIFICATION_ID_TAG) @@ -205,8 +206,8 @@ async function addRuntimeNotification( account.id, recipient, notificationType, - event, - dispatchBlock + dispatchBlock, + event ) const pref = preferencesForNotification(account.notificationPreferences, notificationType) @@ -248,8 +249,8 @@ const createNotification = ( accountId: string, recipient: RecipientType, notificationType: NotificationType, - event?: Event, - dispatchBlock?: number + dispatchBlock: number, + event?: Event ) => { return new Notification({ id, @@ -284,15 +285,16 @@ export const addNotification = async ( recipient, notificationType, event, - dispatchBlock + dispatchBlock || event.inBlock ) } else { + const { lastProcessedBlock } = await getCurrentBlockHeight(store as EntityManager) await addOffChainNotification( store as EntityManager, account, recipient, notificationType, - dispatchBlock + dispatchBlock ?? lastProcessedBlock ) } }