From ab1795dbbe2c3b3504a4f733fd4d4a0dd7019e89 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Wed, 10 Sep 2014 18:26:00 +0400 Subject: [PATCH] Improved FxOS 1.1 PUSH notifications Closes #413 Closes #373 Closes #441 --- app/js/services.js | 24 ++++++++++++------------ app/manifest.webapp | 3 +++ app/partials/error_modal.html | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/app/js/services.js b/app/js/services.js index 32df720f..fbb7ce81 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -351,8 +351,6 @@ angular.module('myApp.services', []) .service('PhonebookContactsService', function ($q, $modal, $sce, FileManager) { - var phonebookContactsPromise; - return { isAvailable: isAvailable, openPhonebookImport: openPhonebookImport, @@ -380,10 +378,6 @@ angular.module('myApp.services', []) } function getPhonebookContacts () { - if (phonebookContactsPromise) { - return phonebookContactsPromise; - } - try { var request = window.navigator.mozContacts.getAll({}); } catch (e) { @@ -435,7 +429,7 @@ angular.module('myApp.services', []) deferred.reject(e); } - return phonebookContactsPromise = deferred.promise; + return deferred.promise; } }) @@ -3489,10 +3483,7 @@ var regexAlphaNumericChars = "0-9\.\_" + regexAlphaChars; } function notify (data) { - // console.log('notify', $rootScope.idle.isIDLE, notificationsUiSupport); - if (!$rootScope.idle.isIDLE) { - return false; - } + console.log('notify', $rootScope.idle.isIDLE, notificationsUiSupport); // FFOS Notification blob src bug workaround if (Config.Navigator.ffos) { @@ -3558,6 +3549,9 @@ var regexAlphaNumericChars = "0-9\.\_" + regexAlphaChars; notificationsClear(); }; + if (notification.show) { + notification.show(); + } notificationsShown[key] = notification; }); }; @@ -3598,6 +3592,8 @@ var regexAlphaNumericChars = "0-9\.\_" + regexAlphaChars; notificationsCount = 0; } + var registerDevicePeriod = 1000, + registerDeviceTO; function registerDevice () { if (registeredDevice) { return false; @@ -3606,6 +3602,8 @@ var regexAlphaNumericChars = "0-9\.\_" + regexAlphaChars; var req = navigator.push.register(); req.onsuccess = function(e) { + clearTimeout(registerDeviceTO); + console.log(dT(), 'Push registered', req.result); registeredDevice = req.result; MtpApiManager.invokeApi('account.registerDevice', { token_type: 4, @@ -3619,7 +3617,9 @@ var regexAlphaNumericChars = "0-9\.\_" + regexAlphaChars; } req.onerror = function(e) { - console.error('Push register error', e); + console.error('Push register error', e, e.toString()); + registerDeviceTO = setTimeout(registerDevice, registerDevicePeriod); + registerDevicePeriod = Math.min(30000, registerDevicePeriod * 1.5); } } } diff --git a/app/manifest.webapp b/app/manifest.webapp index 14086aae..7a1ff828 100644 --- a/app/manifest.webapp +++ b/app/manifest.webapp @@ -15,6 +15,8 @@ "push": "/index.html" }, { "push-register": "/index.html" + }, { + "notification": "/index.html" }], "permissions": { "desktop-notification": { @@ -28,6 +30,7 @@ "description": "Required for notifications" } }, + "orientation": "portrait-primary", "icons": { "16": "/img/icons/icon16.png", "32": "/img/icons/icon32.png", diff --git a/app/partials/error_modal.html b/app/partials/error_modal.html index 2cc09a53..d8115053 100644 --- a/app/partials/error_modal.html +++ b/app/partials/error_modal.html @@ -57,7 +57,7 @@ Sorry, there are no Telegram accounts with the phone numbers you provided. - Telegram need access to phonebook to import contacts. + Telegram needs access to phonebook to import contacts.