From ff9a2166463f9c60d12c59ce7fce7978d29f2fcc Mon Sep 17 00:00:00 2001 From: Josh Kasten Date: Fri, 29 Sep 2023 00:12:20 +0000 Subject: [PATCH 1/2] Re-enable welcome notifications This existing code still uses include_player_ids on the OneSignal REST API POST /notifications. include_player_ids will be dropped by 2025 so a replacement will needed by then. This will most likely be a backend feature which will be a hook on a new push subscription create. --- src/shared/helpers/EventHelper.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/shared/helpers/EventHelper.ts b/src/shared/helpers/EventHelper.ts index 379c1117a..a31cb5d9e 100755 --- a/src/shared/helpers/EventHelper.ts +++ b/src/shared/helpers/EventHelper.ts @@ -85,7 +85,10 @@ export default class EventHelper { static async _onSubscriptionChanged( change: SubscriptionChangeEvent | undefined, ) { - // EventHelper.onSubscriptionChanged_showWelcomeNotification(change?.current.enabled); + EventHelper.onSubscriptionChanged_showWelcomeNotification( + change?.current?.optedIn, + change?.current?.id, + ); EventHelper.onSubscriptionChanged_sendCategorySlidedownTags( change?.current?.optedIn, ); @@ -107,9 +110,15 @@ export default class EventHelper { } } + /** + * NOTE: This uses the OneSignal REST API POST /notifications with + * include_player_ids. This field will be dropped by 2025 so a + * replacement will needed by then. + */ private static sendingOrSentWelcomeNotification = false; private static async onSubscriptionChanged_showWelcomeNotification( isSubscribed: boolean | undefined, + pushSubscriptionId: string | undefined | null, ) { if (OneSignal.__doNotShowWelcomeNotification) { Log.debug( @@ -131,6 +140,10 @@ export default class EventHelper { return; } + if (!pushSubscriptionId) { + return; + } + // Workaround only for this v15 branch; There are race conditions in the SDK // that result in the onSubscriptionChanged firing more than once sometimes. if (EventHelper.sendingOrSentWelcomeNotification) { @@ -138,7 +151,6 @@ export default class EventHelper { } EventHelper.sendingOrSentWelcomeNotification = true; - const { deviceId } = await Database.getSubscription(); const { appId } = await Database.getAppConfig(); let title = welcome_notification_opts !== undefined && @@ -167,7 +179,7 @@ export default class EventHelper { Log.debug('Sending welcome notification.'); OneSignalApiShared.sendNotification( appId, - [deviceId], + [pushSubscriptionId], { en: title }, { en: message }, url, From 03a65def457c4990b091825d5cd1d5b091d8e8de Mon Sep 17 00:00:00 2001 From: Josh Kasten Date: Fri, 29 Sep 2023 00:16:12 +0000 Subject: [PATCH 2/2] rm double welcome send work around logic The event logic was changed in User Model so this is longer an issue with v16. --- src/shared/helpers/EventHelper.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/shared/helpers/EventHelper.ts b/src/shared/helpers/EventHelper.ts index a31cb5d9e..ad359bd86 100755 --- a/src/shared/helpers/EventHelper.ts +++ b/src/shared/helpers/EventHelper.ts @@ -115,7 +115,6 @@ export default class EventHelper { * include_player_ids. This field will be dropped by 2025 so a * replacement will needed by then. */ - private static sendingOrSentWelcomeNotification = false; private static async onSubscriptionChanged_showWelcomeNotification( isSubscribed: boolean | undefined, pushSubscriptionId: string | undefined | null, @@ -144,13 +143,6 @@ export default class EventHelper { return; } - // Workaround only for this v15 branch; There are race conditions in the SDK - // that result in the onSubscriptionChanged firing more than once sometimes. - if (EventHelper.sendingOrSentWelcomeNotification) { - return; - } - EventHelper.sendingOrSentWelcomeNotification = true; - const { appId } = await Database.getAppConfig(); let title = welcome_notification_opts !== undefined &&