From 62a905f0878f0005dcc929ea76fecc08f347e277 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Fri, 4 Jul 2014 21:54:54 +0400 Subject: [PATCH] Added device register for packaged FFOS app --- app/js/lib/mtproto.js | 12 +++++++++++- app/js/services.js | 41 +++++++++++++++++++++++++++++++++++++++++ app/manifest.webapp | 8 ++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/app/js/lib/mtproto.js b/app/js/lib/mtproto.js index 01898a13..7d32d039 100644 --- a/app/js/lib/mtproto.js +++ b/app/js/lib/mtproto.js @@ -256,12 +256,17 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) console.log(dT(), 'PQ factorization start', auth.pq); if (!!window.Worker/* && false*/) { - var worker = new Worker('js/lib/pq_worker.js'); + var worker = new Worker('js/lib/pq_worker.js'), + curRetry = auth.pqRetry, + canceled = false; worker.onmessage = function (e) { auth.p = e.data[0]; auth.q = e.data[1]; console.log(dT(), 'PQ factorization done', e.data[2]); + } catch (e) { + alert(e.message + ' ' + e.stack); + } mtpSendReqDhParams(auth); }; worker.onerror = function(error) { @@ -288,6 +293,11 @@ angular.module('izhukov.mtproto', ['izhukov.utils']) }; function mtpSendReqDhParams (auth) { + + alert('send req dh'); + alert(auth.p); + alert(auth.q); + var deferred = auth.deferred; auth.newNonce = new Array(32); diff --git a/app/js/services.js b/app/js/services.js index 73f5e3a7..d37d6449 100644 --- a/app/js/services.js +++ b/app/js/services.js @@ -3279,6 +3279,7 @@ angular.module('myApp.services', []) } function start () { + registerDevice(); if (!notificationsUiSupport) { return false; } @@ -3389,6 +3390,46 @@ angular.module('myApp.services', []) }); notificationsShown = {}; } + + var registeredDevice = false; + + function registerDevice () { + if (registeredDevice) { + return false; + } + if (navigator.push) { + var req = navigator.push.register(); + + req.onsuccess = function(e) { + registeredDevice = req.result; + MtpApiManager.invokeApi('account.registerDevice', { + token_type: 4, + token: registeredDevice, + device_model: navigator.userAgent || 'Unknown UserAgent', + system_version: navigator.platform || 'Unknown Platform', + app_version: Config.App.version, + app_sandbox: false, + lang_code: navigator.language || 'en' + }); + } + + req.onerror = function(e) { + console.error('Push register error', e); + } + } + } + + function unregisterDevice () { + if (!registeredDevice) { + return false; + } + MtpApiManager.invokeApi('account.unregisterDevice', { + token_type: 4, + token: registeredDevice + }).then(function () { + registeredDevice = false; + }) + } }) diff --git a/app/manifest.webapp b/app/manifest.webapp index ea57817e..e0898414 100644 --- a/app/manifest.webapp +++ b/app/manifest.webapp @@ -11,6 +11,11 @@ "installs_allowed_from": [ "*" ], + "messages": [{ + "push": "/index.html" + }, { + "push-register": "/index.html" + }], "permissions": { "desktop-notification": { "description": "Required to show new message notifications" @@ -18,6 +23,9 @@ "contacts": { "description": "Required to import phonebook contacts", "access": "readonly" + }, + "push": { + "description": "Required for notifications" } }, "icons": {