@@ -82,53 +82,57 @@ export default class EventHelper {
8282 Log . debug ( 'Not showing welcome notification because user has previously subscribed.' ) ;
8383 return ;
8484 }
85- if ( isSubscribed === true ) {
86- const { deviceId } = await Database . getSubscription ( ) ;
87- const { appId } = await Database . getAppConfig ( ) ;
88-
89- const welcome_notification_opts = OneSignal . config . userConfig . welcomeNotification ;
90- const welcome_notification_disabled =
91- welcome_notification_opts !== undefined && welcome_notification_opts [ 'disable' ] === true ;
92- let title =
93- welcome_notification_opts !== undefined &&
94- welcome_notification_opts [ 'title' ] !== undefined &&
95- welcome_notification_opts [ 'title' ] !== null
96- ? welcome_notification_opts [ 'title' ]
97- : '' ;
98- let message =
99- welcome_notification_opts !== undefined &&
100- welcome_notification_opts [ 'message' ] !== undefined &&
101- welcome_notification_opts [ 'message' ] !== null &&
102- welcome_notification_opts [ 'message' ] . length > 0
103- ? welcome_notification_opts [ 'message' ]
104- : 'Thanks for subscribing!' ;
105- const unopenableWelcomeNotificationUrl = new URL ( location . href ) . origin + '?_osp=do_not_open' ;
106- const url =
107- welcome_notification_opts && welcome_notification_opts [ 'url' ] && welcome_notification_opts [ 'url' ] . length > 0
108- ? welcome_notification_opts [ 'url' ]
109- : unopenableWelcomeNotificationUrl ;
110- title = BrowserUtils . decodeHtmlEntities ( title ) ;
111- message = BrowserUtils . decodeHtmlEntities ( message ) ;
112-
113- if ( ! welcome_notification_disabled ) {
114- Log . debug ( 'Sending welcome notification.' ) ;
115- OneSignalApiShared . sendNotification (
116- appId ,
117- [ deviceId ] ,
118- { en : title } ,
119- { en : message } ,
120- url ,
121- null ,
122- { __isOneSignalWelcomeNotification : true } ,
123- undefined
124- ) ;
125- Event . trigger ( OneSignal . EVENTS . WELCOME_NOTIFICATION_SENT , {
126- title : title ,
127- message : message ,
128- url : url
129- } ) ;
130- }
85+ const welcome_notification_opts = OneSignal . config . userConfig . welcomeNotification ;
86+ const welcome_notification_disabled =
87+ welcome_notification_opts !== undefined && welcome_notification_opts [ 'disable' ] === true ;
88+
89+ if ( welcome_notification_disabled ) {
90+ return ;
91+ }
92+
93+ if ( isSubscribed !== true ) {
94+ return ;
13195 }
96+
97+ const { deviceId } = await Database . getSubscription ( ) ;
98+ const { appId } = await Database . getAppConfig ( ) ;
99+ let title =
100+ welcome_notification_opts !== undefined &&
101+ welcome_notification_opts [ 'title' ] !== undefined &&
102+ welcome_notification_opts [ 'title' ] !== null
103+ ? welcome_notification_opts [ 'title' ]
104+ : '' ;
105+ let message =
106+ welcome_notification_opts !== undefined &&
107+ welcome_notification_opts [ 'message' ] !== undefined &&
108+ welcome_notification_opts [ 'message' ] !== null &&
109+ welcome_notification_opts [ 'message' ] . length > 0
110+ ? welcome_notification_opts [ 'message' ]
111+ : 'Thanks for subscribing!' ;
112+ const unopenableWelcomeNotificationUrl = new URL ( location . href ) . origin + '?_osp=do_not_open' ;
113+ const url =
114+ welcome_notification_opts && welcome_notification_opts [ 'url' ] && welcome_notification_opts [ 'url' ] . length > 0
115+ ? welcome_notification_opts [ 'url' ]
116+ : unopenableWelcomeNotificationUrl ;
117+ title = BrowserUtils . decodeHtmlEntities ( title ) ;
118+ message = BrowserUtils . decodeHtmlEntities ( message ) ;
119+
120+ Log . debug ( 'Sending welcome notification.' ) ;
121+ OneSignalApiShared . sendNotification (
122+ appId ,
123+ [ deviceId ] ,
124+ { en : title } ,
125+ { en : message } ,
126+ url ,
127+ null ,
128+ { __isOneSignalWelcomeNotification : true } ,
129+ undefined
130+ ) ;
131+ Event . trigger ( OneSignal . EVENTS . WELCOME_NOTIFICATION_SENT , {
132+ title : title ,
133+ message : message ,
134+ url : url
135+ } ) ;
132136 }
133137
134138 private static async onSubscriptionChanged_evaluateNotifyButtonDisplayPredicate ( ) {
0 commit comments