@@ -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