@@ -2,16 +2,16 @@ import Emitter from "../libraries/Emitter";
22import IndexedDb from "./IndexedDb" ;
33
44import { AppConfig } from "../models/AppConfig" ;
5- import { AppState } from "../models/AppState" ;
5+ import { AppState , ClickedNotifications } from "../models/AppState" ;
66import { Notification } from "../models/Notification" ;
77import { ServiceWorkerState } from "../models/ServiceWorkerState" ;
88import { Subscription } from "../models/Subscription" ;
99import { TestEnvironmentKind } from "../models/TestEnvironmentKind" ;
10- import { Timestamp } from "../models/Timestamp" ;
1110import { WindowEnvironmentKind } from "../models/WindowEnvironmentKind" ;
1211import { EmailProfile } from "../models/EmailProfile" ;
1312import SdkEnvironment from "../managers/SdkEnvironment" ;
1413import OneSignalUtils from "../utils/OneSignalUtils" ;
14+ import Utils from "../utils/Utils" ;
1515
1616enum DatabaseEventName {
1717 SET
@@ -182,12 +182,18 @@ export default class Database {
182182 return config ;
183183 }
184184
185- async getExternalUserId ( ) : Promise < string | undefined > {
185+ async getExternalUserId ( ) : Promise < string | undefined | null > {
186186 return await this . get < string > ( "Ids" , "externalUserId" ) ;
187187 }
188188
189- async setExternalUserId ( externalUserId : string | undefined ) : Promise < void > {
190- return await this . put ( "Ids" , { type : "externalUserId" , id : externalUserId } )
189+ async setExternalUserId ( externalUserId : string | undefined | null ) : Promise < void > {
190+ const emptyString : string = "" ;
191+ const externalIdToSave = Utils . getValueOrDefault ( externalUserId , emptyString ) ;
192+ if ( externalIdToSave === emptyString ) {
193+ await this . remove ( "Ids" , "externalUserId" ) ;
194+ } else {
195+ await this . put ( "Ids" , { type : "externalUserId" , id : externalIdToSave } ) ;
196+ }
191197 }
192198
193199 async setAppConfig ( appConfig : AppConfig ) : Promise < void > {
@@ -212,7 +218,7 @@ export default class Database {
212218 state . defaultNotificationUrl = await this . get < string > ( "Options" , "defaultUrl" ) ;
213219 state . defaultNotificationTitle = await this . get < string > ( "Options" , "defaultTitle" ) ;
214220 state . lastKnownPushEnabled = await this . get < boolean > ( "Options" , "isPushEnabled" ) ;
215- state . clickedNotifications = await this . get < Map < URL , [ Notification , Timestamp ] > > ( "NotificationOpened" ) ;
221+ state . clickedNotifications = await this . get < ClickedNotifications > ( "NotificationOpened" ) ;
216222 return state ;
217223 }
218224
@@ -396,11 +402,11 @@ export default class Database {
396402 return await Database . singletonInstance . getAppConfig ( ) ;
397403 }
398404
399- static async getExternalUserId ( ) : Promise < string | undefined > {
405+ static async getExternalUserId ( ) : Promise < string | undefined | null > {
400406 return await Database . singletonInstance . getExternalUserId ( ) ;
401407 }
402408
403- static async setExternalUserId ( externalUserId : string | undefined ) : Promise < void > {
409+ static async setExternalUserId ( externalUserId : string | undefined | null ) : Promise < void > {
404410 await Database . singletonInstance . setExternalUserId ( externalUserId ) ;
405411 }
406412
0 commit comments