diff --git a/src/core/CoreModuleDirector.ts b/src/core/CoreModuleDirector.ts index 9cf8dae70..7ef1d0cd6 100644 --- a/src/core/CoreModuleDirector.ts +++ b/src/core/CoreModuleDirector.ts @@ -5,6 +5,7 @@ import { OSModel } from './modelRepo/OSModel'; import { SupportedIdentity } from './models/IdentityModel'; import { ModelStoresMap } from './models/ModelStoresMap'; import { + SubscriptionChannel, SubscriptionModel, SubscriptionType, SupportedSubscription, @@ -122,7 +123,7 @@ export class CoreModuleDirector { */ const existingSubscription = !!subscription.token ? this.getSubscriptionOfTypeWithToken( - subscription.type, + this.toSubscriptionChannel(subscription.type), subscription.token, ) : undefined; @@ -260,7 +261,7 @@ export class CoreModuleDirector { const pushToken = await MainHelper.getCurrentPushToken(); if (pushToken) { return this.getSubscriptionOfTypeWithToken( - ModelName.Subscriptions, + SubscriptionChannel.Push, pushToken, ); } @@ -278,7 +279,7 @@ export class CoreModuleDirector { const { lastKnownPushToken } = await Database.getAppState(); if (lastKnownPushToken) { return this.getSubscriptionOfTypeWithToken( - ModelName.Subscriptions, + SubscriptionChannel.Push, lastKnownPushToken, ); } @@ -332,7 +333,7 @@ export class CoreModuleDirector { } public getSubscriptionOfTypeWithToken( - type: SubscriptionType | ModelName.Subscriptions, + type: SubscriptionChannel | undefined, token: string, ): OSModel | undefined { logMethodCall('CoreModuleDirector.getSubscriptionOfTypeWithToken', { @@ -343,21 +344,16 @@ export class CoreModuleDirector { let subscriptions: Record>; switch (type) { - case SubscriptionType.Email: + case SubscriptionChannel.Email: subscriptions = this.getEmailSubscriptionModels(); break; - case SubscriptionType.SMS: + case SubscriptionChannel.SMS: subscriptions = this.getSmsSubscriptionModels(); break; - case ModelName.Subscriptions: + case SubscriptionChannel.Push: subscriptions = this.getAllPushSubscriptionModels(); break; default: - if (this.isPushSubscriptionType(type)) { - subscriptions = this.getAllPushSubscriptionModels(); - break; - } - return undefined; } @@ -386,4 +382,19 @@ export class CoreModuleDirector { return false; } } + + public toSubscriptionChannel(type: SubscriptionType) { + switch (type) { + case SubscriptionType.Email: + return SubscriptionChannel.Email; + case SubscriptionType.SMS: + return SubscriptionChannel.SMS; + default: + if (this.isPushSubscriptionType(type)) { + return SubscriptionChannel.Push; + } + + return undefined; + } + } } diff --git a/src/core/models/SubscriptionModels.ts b/src/core/models/SubscriptionModels.ts index be9c0e3c2..595d02c1a 100644 --- a/src/core/models/SubscriptionModels.ts +++ b/src/core/models/SubscriptionModels.ts @@ -12,6 +12,12 @@ export enum SubscriptionType { // There are other OneSignal types, but only including ones used here. } +export enum SubscriptionChannel { + Email = 'Email', + SMS = 'SMS', + Push = 'Push', +} + export interface FutureSubscriptionModel { type: SubscriptionType; token?: string; // maps to legacy player.identifier