1+ import { IDManager } from 'src/shared/managers/IDManager' ;
2+ import { SubscriptionStateKind } from 'src/shared/models/SubscriptionStateKind' ;
3+ import { SubscriptionType } from '../models/SubscriptionModels' ;
14import { Operation } from './Operation' ;
5+ import { Subscription } from './types' ;
26
37/**
48 * Base class for subscription-related operations
@@ -8,11 +12,20 @@ export abstract class BaseSubscriptionOperation extends Operation {
812 operationName : string ,
913 appId ?: string ,
1014 onesignalId ?: string ,
11- subscriptionId ?: string ,
15+ subscription ?: Subscription ,
1216 ) {
1317 super ( operationName , appId , onesignalId ) ;
14- if ( subscriptionId ) {
15- this . subscriptionId = subscriptionId ;
18+
19+ if ( subscription ) {
20+ this . subscriptionId = subscription . subscriptionId ;
21+ this . type = subscription . type ;
22+ this . enabled = subscription . enabled ;
23+ this . notification_types = subscription . notification_types ;
24+ this . sdk = subscription . sdk ;
25+ this . device_model = subscription . device_model ;
26+ this . device_os = subscription . device_os ;
27+ this . web_auth = subscription . web_auth ;
28+ this . web_p256 = subscription . web_p256 ;
1629 }
1730 }
1831
@@ -27,6 +40,86 @@ export abstract class BaseSubscriptionOperation extends Operation {
2740 this . setProperty < string > ( 'subscriptionId' , value ) ;
2841 }
2942
43+ /**
44+ * The type of subscription.
45+ */
46+ get type ( ) : SubscriptionType {
47+ return this . getProperty < SubscriptionType > ( 'type' ) ;
48+ }
49+ protected set type ( value : SubscriptionType ) {
50+ this . setProperty < SubscriptionType > ( 'type' , value ) ;
51+ }
52+
53+ /**
54+ * Whether this subscription is currently enabled.
55+ */
56+ get enabled ( ) : boolean {
57+ return this . getProperty < boolean > ( 'enabled' ) ;
58+ }
59+ protected set enabled ( value : boolean ) {
60+ this . setProperty < boolean > ( 'enabled' , value ) ;
61+ }
62+
63+ /**
64+ * The notification types this subscription is subscribed to.
65+ */
66+ get notification_types ( ) : SubscriptionStateKind {
67+ return this . getProperty < SubscriptionStateKind > ( 'notification_types' ) ;
68+ }
69+ protected set notification_types ( value : SubscriptionStateKind ) {
70+ this . setProperty < SubscriptionStateKind > ( 'notification_types' , value ) ;
71+ }
72+
73+ /**
74+ * The SDK identifier
75+ */
76+ get sdk ( ) : string | undefined {
77+ return this . getProperty < string | undefined > ( 'sdk' ) ;
78+ }
79+ protected set sdk ( value : string | undefined ) {
80+ this . setProperty < string | undefined > ( 'sdk' , value ) ;
81+ }
82+
83+ /**
84+ * The device model
85+ */
86+ get device_model ( ) : string | undefined {
87+ return this . getProperty < string | undefined > ( 'device_model' ) ;
88+ }
89+ protected set device_model ( value : string | undefined ) {
90+ this . setProperty < string | undefined > ( 'device_model' , value ) ;
91+ }
92+
93+ /**
94+ * The device OS version
95+ */
96+ get device_os ( ) : number | undefined {
97+ return this . getProperty < number | undefined > ( 'device_os' ) ;
98+ }
99+ protected set device_os ( value : number | undefined ) {
100+ this . setProperty < number | undefined > ( 'device_os' , value ) ;
101+ }
102+
103+ /**
104+ * Web authentication value
105+ */
106+ get web_auth ( ) : string | undefined {
107+ return this . getProperty < string | undefined > ( 'web_auth' ) ;
108+ }
109+ protected set web_auth ( value : string | undefined ) {
110+ this . setProperty < string | undefined > ( 'web_auth' , value ) ;
111+ }
112+
113+ /**
114+ * Web P256 value
115+ */
116+ get web_p256 ( ) : string | undefined {
117+ return this . getProperty < string | undefined > ( 'web_p256' ) ;
118+ }
119+ protected set web_p256 ( value : string | undefined ) {
120+ this . setProperty < string | undefined > ( 'web_p256' , value ) ;
121+ }
122+
30123 override get createComparisonKey ( ) : string {
31124 return `${ this . appId } .User.${ this . onesignalId } ` ;
32125 }
@@ -35,6 +128,13 @@ export abstract class BaseSubscriptionOperation extends Operation {
35128 return `${ this . appId } .User.${ this . onesignalId } .Subscription.${ this . subscriptionId } ` ;
36129 }
37130
131+ override get canStartExecute ( ) : boolean {
132+ return (
133+ ! IDManager . isLocalId ( this . onesignalId ) &&
134+ ! IDManager . isLocalId ( this . subscriptionId )
135+ ) ;
136+ }
137+
38138 override get applyToRecordId ( ) : string {
39139 return this . subscriptionId ;
40140 }
0 commit comments