Browse Source

Improved FxOS 1.1 PUSH notifications

Closes #413
Closes #373
Closes #441
master
Igor Zhukov 10 years ago
parent
commit
ab1795dbbe
  1. 24
      app/js/services.js
  2. 3
      app/manifest.webapp
  3. 2
      app/partials/error_modal.html

24
app/js/services.js

@ -351,8 +351,6 @@ angular.module('myApp.services', []) @@ -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', []) @@ -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', []) @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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);
}
}
}

3
app/manifest.webapp

@ -15,6 +15,8 @@ @@ -15,6 +15,8 @@
"push": "/index.html"
}, {
"push-register": "/index.html"
}, {
"notification": "/index.html"
}],
"permissions": {
"desktop-notification": {
@ -28,6 +30,7 @@ @@ -28,6 +30,7 @@
"description": "Required for notifications"
}
},
"orientation": "portrait-primary",
"icons": {
"16": "/img/icons/icon16.png",
"32": "/img/icons/icon32.png",

2
app/partials/error_modal.html

@ -57,7 +57,7 @@ @@ -57,7 +57,7 @@
Sorry, there are no <strong>Telegram</strong> accounts with the phone numbers you provided.
</span>
<span ng-switch-when="PHONEBOOK_GET_CONTACTS_FAILED">
Telegram need access to phonebook to import contacts.
Telegram needs access to phonebook to import contacts.
</span>
<div ng-switch-default ng-switch="error.code">

Loading…
Cancel
Save