Skip to content

Commit

Permalink
typescript migration
Browse files Browse the repository at this point in the history
migrate the file into typescript, including adding the event handling

remove references (all unused)

add init call with others in App.tsx
  • Loading branch information
Abby Wheelis committed Nov 3, 2023
1 parent 9aa89d5 commit 16c87f0
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 71 deletions.
1 change: 0 additions & 1 deletion www/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 2 additions & 0 deletions www/js/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => [
{
Expand Down Expand Up @@ -74,6 +75,7 @@ const App = () => {
});
initPushNotify();
initStoreDeviceSettings();
initRemoteNotifyHandler();
}, [appConfig]);

const appContextValue = {
Expand Down
8 changes: 3 additions & 5 deletions www/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
120 changes: 55 additions & 65 deletions www/js/splash/remoteNotifyHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

0 comments on commit 16c87f0

Please sign in to comment.