1- import { GleapFrameManager , GleapNotificationManager } from "./Gleap" ;
1+ import { GleapEventManager , GleapFrameManager , GleapNotificationManager } from "./Gleap" ;
22import { eraseGleapCookie , getGleapCookie , loadFromGleapCache , saveToGleapCache , setGleapCookie } from "./GleapHelper" ;
33
44export default class GleapSession {
@@ -91,6 +91,10 @@ export default class GleapSession {
9191 } ;
9292
9393 clearSession = ( attemp = 0 , retry = true ) => {
94+ if ( this . session && this . session . gleapHash ) {
95+ GleapEventManager . notifyEvent ( "unregister-pushmessage-group" , `gleapuser-${ this . session . gleapHash } ` ) ;
96+ }
97+
9498 try {
9599 saveToGleapCache ( `session-${ this . sdkKey } ` , null ) ;
96100 } catch ( exp ) { }
@@ -103,13 +107,13 @@ export default class GleapSession {
103107
104108 this . ready = false ;
105109 this . session = {
106- id : null ,
107- hash : null ,
108- type : null ,
110+ gleapId : null ,
111+ gleapHash : null ,
109112 name : "" ,
110113 email : "" ,
114+ userId : "" ,
111115 phone : "" ,
112- value : 0 ,
116+ value : 0
113117 } ;
114118
115119 GleapFrameManager . getInstance ( ) . sendMessage ( {
@@ -134,6 +138,16 @@ export default class GleapSession {
134138 return ;
135139 }
136140
141+ var sessionChanged = true ;
142+ if ( this . session && this . session . gleapHash && this . session . gleapHash === session . gleapHash ) {
143+ sessionChanged = false ;
144+ }
145+
146+ // Unregister previous group.
147+ if ( this . session && this . session . gleapHash && sessionChanged ) {
148+ GleapEventManager . notifyEvent ( "unregister-pushmessage-group" , `gleapuser-${ this . session . gleapHash } ` ) ;
149+ }
150+
137151 saveToGleapCache ( `session-${ this . sdkKey } ` , session ) ;
138152 if ( this . useCookies ) {
139153 setGleapCookie ( `session-${ this . sdkKey } ` , encodeURIComponent ( JSON . stringify ( session ) ) , 365 ) ;
@@ -142,6 +156,11 @@ export default class GleapSession {
142156 this . session = session ;
143157 this . ready = true ;
144158
159+ // Register new push group.
160+ if ( this . session && this . session . gleapHash && sessionChanged ) {
161+ GleapEventManager . notifyEvent ( "register-pushmessage-group" , `gleapuser-${ this . session . gleapHash } ` ) ;
162+ }
163+
145164 this . notifySessionReady ( ) ;
146165 } ;
147166
@@ -285,7 +304,7 @@ export default class GleapSession {
285304 ...userData . customData ,
286305 }
287306 }
288-
307+
289308 http . send (
290309 JSON . stringify ( {
291310 ...dataToSend ,
0 commit comments