diff --git a/www/index.js b/www/index.js index ca1bbcfbb..3aa5be4ed 100644 --- a/www/index.js +++ b/www/index.js @@ -6,7 +6,6 @@ import 'leaflet/dist/leaflet.css'; import './js/ngApp.js'; import './js/splash/referral.js'; import './js/splash/localnotify.js'; -import './js/splash/remotenotify.js'; import './js/splash/notifScheduler.js'; import './js/controllers.js'; import './js/services.js'; diff --git a/www/js/App.tsx b/www/js/App.tsx index dbbef406c..e6b09b3ee 100644 --- a/www/js/App.tsx +++ b/www/js/App.tsx @@ -17,6 +17,7 @@ import AppStatusModal from './control/AppStatusModal'; import usePermissionStatus from './usePermissionStatus'; import { initPushNotify } from './splash/pushNotifySettings'; import { initStoreDeviceSettings } from './splash/storeDeviceSettings'; +import { initRemoteNotifyHandler } from './splash/remoteNotifyHandler'; const defaultRoutes = (t) => [ { @@ -74,6 +75,7 @@ const App = () => { }); initPushNotify(); initStoreDeviceSettings(); + initRemoteNotifyHandler(); }, [appConfig]); const appContextValue = { diff --git a/www/js/controllers.js b/www/js/controllers.js index e502dda2e..ee29af103 100644 --- a/www/js/controllers.js +++ b/www/js/controllers.js @@ -5,18 +5,16 @@ import { addStatError, addStatReading, statKeys } from './plugin/clientStats'; import { getPendingOnboardingState } from './onboarding/onboardingHelper'; angular - .module('emission.controllers', ['emission.splash.localnotify', 'emission.splash.remotenotify']) + .module('emission.controllers', ['emission.splash.localnotify']) .controller('RootCtrl', function ($scope) {}) .controller('DashCtrl', function ($scope) {}) - .controller( - 'SplashCtrl', - function ($scope, $state, $interval, $rootScope, LocalNotify, RemoteNotify) { - console.log('SplashCtrl invoked'); // alert("attach debugger!"); // PushNotify.startupInit(); + .controller('SplashCtrl', function ($scope, $state, $interval, $rootScope, LocalNotify) { + console.log('SplashCtrl invoked'); $rootScope.$on( '$stateChangeSuccess', diff --git a/www/js/splash/remoteNotifyHandler.ts b/www/js/splash/remoteNotifyHandler.ts index a59fdf376..0be6ca201 100644 --- a/www/js/splash/remoteNotifyHandler.ts +++ b/www/js/splash/remoteNotifyHandler.ts @@ -16,76 +16,66 @@ 'use strict'; import angular from 'angular'; +import { EVENT_NAMES, subscribe } from '../customEventHandler'; import { addStatEvent, statKeys } from '../plugin/clientStats'; +import { displayErrorMsg, logDebug } from '../plugin/logger'; -angular - .module('emission.splash.remotenotify', ['emission.plugin.logger']) +const options = 'location=yes,clearcache=no,toolbar=yes,hideurlbar=yes'; - .factory('RemoteNotify', function ($http, $window, $ionicPopup, $rootScope, Logger) { - var remoteNotify = {}; - remoteNotify.options = 'location=yes,clearcache=no,toolbar=yes,hideurlbar=yes'; - - /* +/* TODO: Potentially unify with the survey URL loading */ - remoteNotify.launchWebpage = function (url) { - // THIS LINE FOR inAppBrowser - let iab = $window.cordova.InAppBrowser.open(url, '_blank', remoteNotify.options); - }; +const launchWebpage = function (url) { + // THIS LINE FOR inAppBrowser + let iab = window['cordova'].InAppBrowser.open(url, '_blank', options); +}; - remoteNotify.launchPopup = function (title, text) { - // THIS LINE FOR inAppBrowser - let alertPopup = $ionicPopup.alert({ - title: title, - template: text, - }); - }; +const launchPopup = function (title, text) { + // THIS LINE FOR inAppBrowser + displayErrorMsg(text, title); +}; - remoteNotify.init = function () { - $rootScope.$on('cloud:push:notification', function (event, data) { - addStatEvent(statKeys.NOTIFICATION_OPEN).then(() => { - console.log( - 'Added ' + statKeys.NOTIFICATION_OPEN + ' event. Data = ' + JSON.stringify(data), - ); - }); - Logger.log('data = ' + JSON.stringify(data)); - if ( - angular.isDefined(data.additionalData) && - angular.isDefined(data.additionalData.payload) && - angular.isDefined(data.additionalData.payload.alert_type) - ) { - if (data.additionalData.payload.alert_type == 'website') { - var webpage_spec = data.additionalData.payload.spec; - if ( - angular.isDefined(webpage_spec) && - angular.isDefined(webpage_spec.url) && - webpage_spec.url.startsWith('https://') - ) { - remoteNotify.launchWebpage(webpage_spec.url); - } else { - $ionicPopup.alert( - 'webpage was not specified correctly. spec is ' + JSON.stringify(webpage_spec), - ); - } - } - if (data.additionalData.payload.alert_type == 'popup') { - var popup_spec = data.additionalData.payload.spec; - if ( - angular.isDefined(popup_spec) && - angular.isDefined(popup_spec.title) && - angular.isDefined(popup_spec.text) - ) { - remoteNotify.launchPopup(popup_spec.title, popup_spec.text); - } else { - $ionicPopup.alert( - 'webpage was not specified correctly. spec is ' + JSON.stringify(popup_spec), - ); - } - } - } - }); - }; - - remoteNotify.init(); - return remoteNotify; +const onCloudNotifEvent = (event) => { + const data = event.detail; + addStatEvent(statKeys.NOTIFICATION_OPEN).then(() => { + console.log('Added ' + statKeys.NOTIFICATION_OPEN + ' event. Data = ' + JSON.stringify(data)); }); + logDebug('data = ' + JSON.stringify(data)); + if ( + angular.isDefined(data.additionalData) && + angular.isDefined(data.additionalData.payload) && + angular.isDefined(data.additionalData.payload.alert_type) + ) { + if (data.additionalData.payload.alert_type == 'website') { + var webpage_spec = data.additionalData.payload.spec; + if ( + angular.isDefined(webpage_spec) && + angular.isDefined(webpage_spec.url) && + webpage_spec.url.startsWith('https://') + ) { + launchWebpage(webpage_spec.url); + } else { + displayErrorMsg( + JSON.stringify(webpage_spec), + 'webpage was not specified correctly. spec is ', + ); + } + } + if (data.additionalData.payload.alert_type == 'popup') { + var popup_spec = data.additionalData.payload.spec; + if ( + angular.isDefined(popup_spec) && + angular.isDefined(popup_spec.title) && + angular.isDefined(popup_spec.text) + ) { + launchPopup(popup_spec.title, popup_spec.text); + } else { + displayErrorMsg(JSON.stringify(popup_spec), 'popup was not specified correctly. spec is '); + } + } + } +}; + +export const initRemoteNotifyHandler = function () { + subscribe(EVENT_NAMES.CLOUD_NOTIFICATION_EVENT, onCloudNotifEvent); +};