Skip to content

Commit 11d6b0b

Browse files
committed
ensure welcome notification is only sent once
In some rare cases iOS WebApps send two welcome notifications. Adding a simple boolean state to prevent this as a simple workaround for this v15 branch.
1 parent 137c998 commit 11d6b0b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/helpers/EventHelper.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export default class EventHelper {
7777
}
7878
}
7979

80+
private static sendingOrSentWelcomeNotification = false;
8081
private static async onSubscriptionChanged_showWelcomeNotification(isSubscribed: boolean | undefined) {
8182
if (OneSignal.__doNotShowWelcomeNotification) {
8283
Log.debug('Not showing welcome notification because user has previously subscribed.');
@@ -94,6 +95,13 @@ export default class EventHelper {
9495
return;
9596
}
9697

98+
// Workaround only for this v15 branch; There are race conditions in the SDK
99+
// that result in the onSubscriptionChanged firing more than once sometimes.
100+
if (EventHelper.sendingOrSentWelcomeNotification) {
101+
return;
102+
}
103+
EventHelper.sendingOrSentWelcomeNotification = true;
104+
97105
const { deviceId } = await Database.getSubscription();
98106
const { appId } = await Database.getAppConfig();
99107
let title =

0 commit comments

Comments
 (0)