Skip to content

Commit 294dddf

Browse files
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
1 parent 42a29e9 commit 294dddf

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
# 4.0.4
1+
# 4.0.6
2+
3+
## Bug Fixes:
4+
- 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)
5+
6+
# 4.0.5
27

38
## Bug Fixes:
49
- 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)

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "orion",
3-
"version": "4.0.5",
3+
"version": "4.0.6",
44
"engines": {
55
"node": ">=16"
66
},

src/utils/notification/helpers.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
RecipientType,
1313
Unread,
1414
} from '../../model'
15+
import { getCurrentBlockHeight } from '../blockHeight'
1516
import { uniqueId } from '../crypto'
1617
import { getNextIdForEntity } from '../nextEntityId'
1718
import { EntityManagerOverlay } from '../overlay'
@@ -153,7 +154,7 @@ async function addOffChainNotification(
153154
account: Flat<Account>,
154155
recipient: RecipientType,
155156
notificationType: NotificationType,
156-
dispatchBlock?: number
157+
dispatchBlock: number
157158
) {
158159
// get notification Id from orion_db in any case
159160
const nextNotificationId = await getNextIdForEntity(em, OFFCHAIN_NOTIFICATION_ID_TAG)
@@ -163,8 +164,8 @@ async function addOffChainNotification(
163164
account.id,
164165
recipient,
165166
notificationType,
166-
undefined,
167-
dispatchBlock
167+
dispatchBlock,
168+
undefined
168169
)
169170

170171
const pref = preferencesForNotification(account.notificationPreferences, notificationType)
@@ -184,7 +185,7 @@ async function addRuntimeNotification(
184185
recipient: RecipientType,
185186
notificationType: NotificationType,
186187
event: Event,
187-
dispatchBlock?: number
188+
dispatchBlock: number
188189
) {
189190
// get notification Id from orion_db in any case
190191
const nextNotificationId = await getNextIdForEntity(overlay, RUNTIME_NOTIFICATION_ID_TAG)
@@ -205,8 +206,8 @@ async function addRuntimeNotification(
205206
account.id,
206207
recipient,
207208
notificationType,
208-
event,
209-
dispatchBlock
209+
dispatchBlock,
210+
event
210211
)
211212

212213
const pref = preferencesForNotification(account.notificationPreferences, notificationType)
@@ -248,8 +249,8 @@ const createNotification = (
248249
accountId: string,
249250
recipient: RecipientType,
250251
notificationType: NotificationType,
251-
event?: Event,
252-
dispatchBlock?: number
252+
dispatchBlock: number,
253+
event?: Event
253254
) => {
254255
return new Notification({
255256
id,
@@ -284,15 +285,16 @@ export const addNotification = async (
284285
recipient,
285286
notificationType,
286287
event,
287-
dispatchBlock
288+
dispatchBlock || event.inBlock
288289
)
289290
} else {
291+
const { lastProcessedBlock } = await getCurrentBlockHeight(store as EntityManager)
290292
await addOffChainNotification(
291293
store as EntityManager,
292294
account,
293295
recipient,
294296
notificationType,
295-
dispatchBlock
297+
dispatchBlock ?? lastProcessedBlock
296298
)
297299
}
298300
}

0 commit comments

Comments
 (0)