Skip to content

Commit a4f3129

Browse files
committed
remove old dead existingToken code
Logic in checkAndTriggerSubscriptionChanged has completely replaced the existingToken* fields in RawPushSubscription. It seem the usages of these fields were dropped in at least v16 beta6, if not sooner.
1 parent 700105c commit a4f3129

File tree

3 files changed

+7
-59
lines changed

3 files changed

+7
-59
lines changed

src/shared/helpers/SubscriptionHelper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ export default class SubscriptionHelper {
120120
static getRawPushSubscriptionForLegacySafari(safariWebId: string): RawPushSubscription {
121121
const subscription = new RawPushSubscription();
122122

123-
const { deviceToken: existingDeviceToken } = window.safari.pushNotification.permission(safariWebId);
124-
subscription.existingSafariDeviceToken = existingDeviceToken;
123+
const { deviceToken } = window.safari.pushNotification.permission(safariWebId);
124+
subscription.setFromSafariSubscription(deviceToken);
125125

126126
return subscription;
127127
}

src/shared/managers/SubscriptionManager.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,6 @@ export class SubscriptionManager {
366366
}
367367

368368
const { deviceToken: existingDeviceToken } = window.safari.pushNotification.permission(this.config.safariWebId);
369-
pushSubscriptionDetails.existingSafariDeviceToken = existingDeviceToken;
370-
371369
if (!existingDeviceToken) {
372370
/*
373371
We're about to show the Safari native permission request. It can fail for a number of
@@ -605,10 +603,6 @@ export class SubscriptionManager {
605603

606604
// Create our own custom object from the browser's native PushSubscription object
607605
const pushSubscriptionDetails = RawPushSubscription.setFromW3cSubscription(newPushSubscription);
608-
if (existingPushSubscription) {
609-
pushSubscriptionDetails.existingW3cPushSubscription =
610-
RawPushSubscription.setFromW3cSubscription(existingPushSubscription);
611-
}
612606
return pushSubscriptionDetails;
613607
}
614608

src/shared/models/RawPushSubscription.ts

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,8 @@ export class RawPushSubscription implements Serializable {
99
w3cAuth: string | undefined;
1010
/**
1111
* A Safari-only push subscription device token. Not used for Chrome/Firefox.
12-
*/
12+
*/
1313
safariDeviceToken: string | undefined;
14-
/**
15-
* A full RawPushSubscription object of the existing W3C subscription, if any.
16-
*
17-
* This is used to determine whether the subscription changed, so we know
18-
* whether to contact OneSignal to update the subscription.
19-
*/
20-
existingW3cPushSubscription: RawPushSubscription | undefined;
21-
/**
22-
* The existing Safari subscription device token, if it exists.
23-
*
24-
* This is used to determine whether the subscription changed, so we know
25-
* whether to contact OneSignal to update the subscription.
26-
*/
27-
existingSafariDeviceToken: string | undefined | null;
28-
29-
/**
30-
* Returns true if an existing recorded W3C or Safari subscription is
31-
* identical to the current subscription.
32-
*/
33-
public isNewSubscription(): boolean {
34-
if (this.existingW3cPushSubscription) {
35-
if (!!this.existingW3cPushSubscription.w3cEndpoint !== !!this.w3cEndpoint) {
36-
return true;
37-
}
38-
if (!!this.existingW3cPushSubscription.w3cEndpoint && !!this.w3cEndpoint &&
39-
this.existingW3cPushSubscription.w3cEndpoint.toString() !== this.w3cEndpoint.toString()) {
40-
return true;
41-
}
42-
if (this.existingW3cPushSubscription.w3cP256dh !== this.w3cP256dh) {
43-
return true;
44-
}
45-
if (this.existingW3cPushSubscription.w3cAuth !== this.w3cAuth) {
46-
return true;
47-
}
48-
return false;
49-
} else if (this.existingSafariDeviceToken) {
50-
return this.existingSafariDeviceToken !== this.safariDeviceToken;
51-
}
52-
return true;
53-
}
5414

5515
/**
5616
* Given a native W3C browser push subscription, takes the endpoint, p256dh,
@@ -102,7 +62,10 @@ export class RawPushSubscription implements Serializable {
10262
*
10363
* @param safariDeviceToken A native browser Safari push subscription.
10464
*/
105-
public setFromSafariSubscription(safariDeviceToken: string) {
65+
public setFromSafariSubscription(safariDeviceToken?: string | null) {
66+
if (!safariDeviceToken) {
67+
return;
68+
}
10669
this.safariDeviceToken = safariDeviceToken;
10770
}
10871

@@ -113,8 +76,6 @@ export class RawPushSubscription implements Serializable {
11376
w3cP256dh: this.w3cP256dh,
11477
w3cAuth: this.w3cAuth,
11578
safariDeviceToken: this.safariDeviceToken,
116-
existingPushSubscription: this.existingW3cPushSubscription ? this.existingW3cPushSubscription.serialize() : null,
117-
existingSafariDeviceToken: this.existingSafariDeviceToken
11879
};
11980

12081
return serializedBundle;
@@ -134,14 +95,7 @@ export class RawPushSubscription implements Serializable {
13495
}
13596
subscription.w3cP256dh = bundle.w3cP256dh;
13697
subscription.w3cAuth = bundle.w3cAuth;
137-
subscription.existingW3cPushSubscription = undefined;
138-
if (bundle.existingW3cPushSubscription) {
139-
subscription.existingW3cPushSubscription = RawPushSubscription.deserialize(bundle.existingW3cPushSubscription);
140-
} else if (bundle.existingPushSubscription) {
141-
subscription.existingW3cPushSubscription = RawPushSubscription.deserialize(bundle.existingPushSubscription);
142-
}
14398
subscription.safariDeviceToken = bundle.safariDeviceToken;
144-
subscription.existingSafariDeviceToken = bundle.existingSafariDeviceToken;
14599
return subscription;
146100
}
147101
}

0 commit comments

Comments
 (0)