@@ -10,7 +10,7 @@ import type {
1010import PubSub from "pubsub-js" ;
1111
1212import type { SirenProviderConfigProps } from "../types" ;
13- import { logger } from "../utils/commonUtils" ;
13+ import { generateUniqueId , logger } from "../utils/commonUtils" ;
1414import {
1515 AUTHENTICATION_FAILED ,
1616 events ,
@@ -24,6 +24,7 @@ import {
2424type SirenContextProp = {
2525 siren : Siren | null ;
2626 verificationStatus : VerificationStatus ;
27+ id : string ;
2728} ;
2829
2930interface SirenProvider {
@@ -34,6 +35,7 @@ interface SirenProvider {
3435export const SirenContext = createContext < SirenContextProp > ( {
3536 siren : null ,
3637 verificationStatus : VerificationStatus . PENDING ,
38+ id : ''
3739} ) ;
3840
3941/**
@@ -42,7 +44,8 @@ export const SirenContext = createContext<SirenContextProp>({
4244 * @example
4345 * const {
4446 * siren,
45- * verificationStatus
47+ * verificationStatus,
48+ * id
4649 * } = useSirenContext();
4750 *
4851 * @returns {SirenContextProp } The Siren notifications context.
@@ -75,6 +78,9 @@ const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {
7578 const [ verificationStatus , setVerificationStatus ] =
7679 useState < VerificationStatus > ( VerificationStatus . PENDING ) ;
7780 let retryCount = 0 ;
81+
82+
83+ const [ id ] = useState ( generateUniqueId ( ) ) ;
7884
7985 useEffect ( ( ) => {
8086 if ( config ?. recipientId && config ?. userToken ) {
@@ -101,14 +107,8 @@ const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {
101107 action : eventTypes . RESET_NOTIFICATIONS ,
102108 } ;
103109
104- PubSub . publish (
105- events . NOTIFICATION_COUNT_EVENT ,
106- JSON . stringify ( updateCountPayload )
107- ) ;
108- PubSub . publish (
109- events . NOTIFICATION_LIST_EVENT ,
110- JSON . stringify ( updateNotificationPayload )
111- ) ;
110+ PubSub . publish ( `${ events . NOTIFICATION_COUNT_EVENT } ${ id } ` , JSON . stringify ( updateCountPayload ) ) ;
111+ PubSub . publish ( `${ events . NOTIFICATION_LIST_EVENT } ${ id } ` , JSON . stringify ( updateNotificationPayload ) ) ;
112112 } ;
113113
114114 const onEventReceive = (
@@ -121,7 +121,7 @@ const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {
121121
122122 logger . info ( `new notifications : ${ JSON . stringify ( newNotifications ) } ` ) ;
123123 PubSub . publish (
124- events . NOTIFICATION_LIST_EVENT ,
124+ ` ${ events . NOTIFICATION_LIST_EVENT } ${ id } ` ,
125125 JSON . stringify ( {
126126 newNotifications,
127127 action : eventTypes . NEW_NOTIFICATIONS ,
@@ -135,10 +135,10 @@ const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {
135135
136136 logger . info ( `unviewed notification count : ${ totalUnviewed } ` ) ;
137137 PubSub . publish (
138- events . NOTIFICATION_COUNT_EVENT ,
138+ ` ${ events . NOTIFICATION_COUNT_EVENT } ${ id } ` ,
139139 JSON . stringify ( {
140140 unviewedCount : totalUnviewed ,
141- action : eventTypes . UPDATE_NOTIFICATIONS_COUNT ,
141+ action : eventTypes . UPDATE_NOTIFICATIONS_COUNT
142142 } )
143143 ) ;
144144 }
@@ -182,6 +182,7 @@ const SirenProvider: React.FC<SirenProvider> = ({ config, children }) => {
182182 return (
183183 < SirenContext . Provider
184184 value = { {
185+ id,
185186 siren,
186187 verificationStatus,
187188 } }
0 commit comments