diff --git a/src/core/CoreModuleDirector.ts b/src/core/CoreModuleDirector.ts index 7ef1d0cd6..a858564c4 100644 --- a/src/core/CoreModuleDirector.ts +++ b/src/core/CoreModuleDirector.ts @@ -21,6 +21,7 @@ import User from '../onesignal/User'; import OneSignal from '../onesignal/OneSignal'; import Database from '../shared/services/Database'; import EventHelper from '../shared/helpers/EventHelper'; +import SubscriptionHelper from '../../src/shared/helpers/SubscriptionHelper'; /* Contains OneSignal User-Model-specific logic*/ @@ -123,7 +124,7 @@ export class CoreModuleDirector { */ const existingSubscription = !!subscription.token ? this.getSubscriptionOfTypeWithToken( - this.toSubscriptionChannel(subscription.type), + SubscriptionHelper.toSubscriptionChannel(subscription.type), subscription.token, ) : undefined; @@ -247,7 +248,7 @@ export class CoreModuleDirector { const pushSubscriptions = Object.fromEntries( Object.entries(subscriptionModels).filter(([, model]) => - this.isPushSubscriptionType(model.data?.type), + SubscriptionHelper.isPushSubscriptionType(model.data?.type), ), ); @@ -367,34 +368,4 @@ export class CoreModuleDirector { private getModelStores(): ModelStoresMap { return this.core.modelRepo?.modelStores as ModelStoresMap; } - - /** - * Helper that checks if a given SubscriptionType is a push subscription. - */ - public isPushSubscriptionType(type: SubscriptionType): boolean { - switch (type) { - case SubscriptionType.ChromePush: - case SubscriptionType.SafariPush: - case SubscriptionType.SafariLegacyPush: - case SubscriptionType.FirefoxPush: - return true; - default: - 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/shared/helpers/SubscriptionHelper.ts b/src/shared/helpers/SubscriptionHelper.ts index e23cae3c3..80b47f38b 100755 --- a/src/shared/helpers/SubscriptionHelper.ts +++ b/src/shared/helpers/SubscriptionHelper.ts @@ -10,6 +10,10 @@ import Log from '../libraries/Log'; import { ContextSWInterface } from '../models/ContextSW'; import SdkEnvironment from '../managers/SdkEnvironment'; import { PermissionUtils } from '../utils/PermissionUtils'; +import { + SubscriptionChannel, + SubscriptionType, +} from '../../../src/core/models/SubscriptionModels'; export default class SubscriptionHelper { public static async registerForPush(): Promise { @@ -43,4 +47,35 @@ export default class SubscriptionHelper { return subscription; } + + /** + * Helper that checks if a given SubscriptionType is a push subscription. + */ + public static isPushSubscriptionType(type: SubscriptionType): boolean { + switch (type) { + case SubscriptionType.ChromePush: + case SubscriptionType.SafariPush: + case SubscriptionType.SafariLegacyPush: + case SubscriptionType.FirefoxPush: + return true; + default: + return false; + } + } + + public static toSubscriptionChannel( + type: SubscriptionType, + ): SubscriptionChannel | undefined { + switch (type) { + case SubscriptionType.Email: + return SubscriptionChannel.Email; + case SubscriptionType.SMS: + return SubscriptionChannel.SMS; + default: + if (this.isPushSubscriptionType(type)) { + return SubscriptionChannel.Push; + } + return undefined; + } + } }