@@ -249,6 +249,7 @@ const isSubscribed = Boolean(subscription)
249
249
scope : ScopeMap
250
250
expiry : number
251
251
symkey : string
252
+ unreadCount : number
252
253
}
253
254
```
254
255
@@ -307,6 +308,7 @@ client.watchSubscriptions(subscriptions => console.log({ subscriptions }))
307
308
scope : ScopeMap
308
309
expiry : number
309
310
symkey : string
311
+ unreadCount : number
310
312
}
311
313
```
312
314
@@ -330,24 +332,75 @@ Get notifications
330
332
// watch notifications of current account's subscription to current dapp
331
333
const notificationsPerPage = 5
332
334
const isInfiniteScroll = true
335
+ const unreadFirst = true
336
+
337
+ const {
338
+ data : notifications,
339
+ nextPage,
340
+ markNotificationsAsRead,
341
+ markAllNotificationsAsRead
342
+ } = useNotifications (
343
+ notificationsPerPage ,
344
+ isInfiniteScroll ,
345
+ account ,
346
+ domain ,
347
+ unreadFirst ,
348
+ onRead // optional function to run whenever messages are read
349
+ )
350
+
351
+ // marking a single notification as read
352
+ await notifications [0 ].markAsRead ();
353
+
354
+ // mark specific notifications as read for default account and under default domain
355
+ await markNotificationsAsRead (notifications .slice (2 ).map (n => n .id ));
356
+
357
+ // mark specific notifications as read for specified account under default domain
358
+ await markNotificationsAsRead (notifications .slice (2 ).map (n => n .id ), differentAccount );
359
+
360
+ // mark specific notifications as read for default account under specified domain
361
+ await markNotificationsAsRead (notifications .slice (2 ).map (n => n .id ), undefined , differentDomain );
362
+
363
+ // mark specific notifications as read for specified account under specified domain
364
+ await markNotificationsAsRead (notifications .slice (2 ).map (n => n .id ), differentAccount , differentDomain );
365
+
366
+ // mark all notifications as read for default account under default domain
367
+ await markAllNotificationsAsRead ();
368
+
369
+ // mark all notifications as read for specified account under default domain
370
+ await markAllNotificationsAsRead (differentAccount );
371
+
372
+ // mark all notifications as read for default account under specified domain
373
+ await markAllNotificationsAsRead (undefined , differentDomain );
374
+
375
+ // mark all notifications as read for specified account under specified domain
376
+ await markAllNotificationsAsRead (differentAccount , differentDomain );
377
+
333
378
334
- const { data : notifications, nextPage } = useNotifications (notificationsPerPage , isInfiniteScroll )
335
379
```
336
380
337
381
#### References
338
382
339
- - ** notificationsPerPage:** Number representing how many notifications to get per fetch
340
- - ** isInfiniteScroll:** Whether or not to keep already fetched notifications when getting next page
383
+ - ** useNotifications()**
384
+ - ** notificationsPerPage:** Number representing how many notifications to get per fetch
385
+ - ** isInfiniteScroll:** Whether or not to keep already fetched notifications when getting next page
386
+ - ** params:** (optional) Additional parameters
387
+ - ** unreadFirst:** (optional, default ` true ` , since 1.3.0) Whether or not unread messages should be sorted at the top, regardless of timestamp
388
+ - ** nextPage:** A function to be called to fetch the next page of notifications
341
389
- ** notifications:** Array of notifications, of type
390
+ - ** notification.read:** Mark the notification as read
391
+ - ** markNotificationsAsRead** : Takes an array of notification IDs and marks them as read. Max 1000 IDs
392
+ - ** markAllNotificationsAsRead** : Mark all notifications as read.
342
393
343
394
``` ts
344
395
{
345
396
title : string
346
397
sentAt : number
347
398
body : string
348
399
id : string
400
+ isRead : boolean
349
401
url : string | null
350
402
type : string
403
+ markAsRead : () => Promise < void >
351
404
}
352
405
```
353
406
@@ -365,26 +418,61 @@ const notificationsPage = client.getNotificationHistory({
365
418
366
419
const notificationsPerPage = 5
367
420
const isInfiniteScroll = true
421
+ const unreadFirst = true
368
422
369
- const { nextPage } = client .pageNotifications (notificationsPerPage , isInfiniteScroll )(onUpdate )
423
+ let notifications = []
424
+
425
+ const onUpdate = ({notifications : fetchedNotifications }: GetNotificationsReturn ) => {
426
+ notifications = fetchedNotifications
427
+ }
428
+
429
+ const {
430
+ nextPage,
431
+ markNotificationAsRead,
432
+ markAllNotificationsAsRead
433
+ } = client .pageNotifications (
434
+ notificationsPerPage ,
435
+ isInfiniteScroll ,
436
+ specifiedAccount // OR undefined,
437
+ specifiedDomain // OR undefined,
438
+ unreadFirst
439
+ )(onUpdate )
440
+
441
+
442
+ // marking a single notification as read
443
+ await notifications [0 ].markAsRead ();
444
+
445
+ // mark specific notifications as read
446
+ await markNotificationsAsRead (notifications .slice (2 ).map (n => n .id ));
447
+
448
+ // mark all notifications as read
449
+ await markAllNotificationsAsRead ();
370
450
```
371
451
372
452
#### References
373
453
374
- - ** notificationsPerPage:** Number representing how many notifications to get per fetch
375
- - ** isInfiniteScroll:** Whether or not to keep already fetched notifications when getting next page
454
+ - ** pageNotifications:**
455
+ - ** notificationsPerPage:** Number representing how many notifications to get per fetch
456
+ - ** isInfiniteScroll:** Whether or not to keep already fetched notifications when getting next page
457
+ - ** params:* (optional) Additional parameters
458
+ - ** unreadFirst:** (optional, default ` true ` , since 1.3.0) Whether or not unread messages should be sorted at the top, regardless of timestamp
376
459
- ** onUpdate:** : A callback that will be called whenever notifications get updated
377
460
- ** nextPage:** : A function to be called to fetch the next page of notifications
378
461
- ** notifications:** Array of notifications, of type
462
+ - ** notification.markAsRead:** Mark the notification as read
463
+ - ** markNotificationsAsRead** : Takes an array of notification IDs and marks them as read. Max 1000 IDs
464
+ - ** markAllNotificationsAsRead** : Mark all notifications as read.
379
465
380
466
``` ts
381
467
{
382
468
title : string
383
469
sentAt : number
384
470
body : string
385
471
id : string
472
+ isRead : boolean // since 1.3.0
386
473
url : string | null
387
474
type : string
475
+ read : () => Promise < void > // since 1.3.0
388
476
}
389
477
```
390
478
0 commit comments