Skip to content

Commit

Permalink
just call the functions
Browse files Browse the repository at this point in the history
trialing calling the functions directly rather than relying on the events

e-mission/e-mission-docs#1024 (comment)
  • Loading branch information
Abby Wheelis committed Oct 31, 2023
1 parent 2e40916 commit cfbc675
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 69 deletions.
20 changes: 0 additions & 20 deletions www/js/splash/notificationCenter.ts

This file was deleted.

31 changes: 12 additions & 19 deletions www/js/splash/pushNotifySettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
* notification handling gets more complex, we should consider decoupling it as well.
*/

import { getAngularService } from '../angular-react-helper';
import { updateUser } from '../commHelper';
import { logDebug, displayError } from '../plugin/logger';
import { subscribe, publish } from './notificationCenter';

let push = null;
const CLOUD_NOTIFICATION_EVENT = 'cloud:push:notification';
let handlerRegistered;

const startupInit = function () {
push = window['PushNotification'].init({
Expand Down Expand Up @@ -51,7 +49,10 @@ const startupInit = function () {
logDebug("No additional data defined, nothing to parse");
}
}
publish(CLOUD_NOTIFICATION_EVENT, data);
//handle the notifucation in pushNotify and remoteNotify
const RemoteNotify = getAngularService("RemoteNotify");
RemoteNotify.onNotification(data);
pushNotification(data);
});
}

Expand All @@ -74,9 +75,7 @@ const registerPromise = function () {
}

export const registerPush = function () {
//register the handler -- executes the first time
//working around no longer using the angular platform ready
registerNotificationHandler();
console.log("register push is called");
registerPromise().then(function (t) {
// alert("Token = "+JSON.stringify(t));
logDebug("Token = " + JSON.stringify(t));
Expand All @@ -101,7 +100,7 @@ export const registerPush = function () {
});
}

var redirectSilentPush = function (event, data) {
const redirectSilentPush = function (data) {
logDebug("Found silent push notification, for platform " + window['cordova'].platformId);
if (window['cordova'].platformId != 'ios') {
logDebug("Platform is not ios, handleSilentPush is not implemented or needed");
Expand Down Expand Up @@ -133,7 +132,7 @@ var redirectSilentPush = function (event, data) {
});
}

var showDebugLocalNotification = function (message) {
const showDebugLocalNotification = function (message) {
window['cordova'].plugins.BEMDataCollection.getConfig().then(function (config) {
if (config.simulate_user_interaction) {
window['cordova'].plugins.notification.local.schedule({
Expand All @@ -147,15 +146,9 @@ var showDebugLocalNotification = function (message) {
});
}

const registerNotificationHandler = function () {
//in order to prevent double - registration
if (!handlerRegistered) {
handlerRegistered = true;
subscribe(CLOUD_NOTIFICATION_EVENT, 'pushNotification', function (event, data) {
logDebug("data = " + JSON.stringify(data));
const pushNotification = function(data) {
logDebug("data = " + JSON.stringify(data));
if (data.additionalData["content-available"] == 1) {
redirectSilentPush(event, data);
redirectSilentPush(data);
}; // else no need to call finish
});
}
};
}
91 changes: 61 additions & 30 deletions www/js/splash/remotenotify.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,37 +41,68 @@ angular.module('emission.splash.remotenotify', ['emission.plugin.logger'])
});
}

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.onNotification = function(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 = 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();
Expand Down

0 comments on commit cfbc675

Please sign in to comment.