From de9b7e2b95a9888767530a9c65af266f171d122c Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Mon, 2 Nov 2015 13:44:05 +0300 Subject: [PATCH] bugfixes --- app/js/controllers.js | 4 ++++ app/js/lib/mtproto_wrapper.js | 32 +++++++++++++++++++++++++++++--- app/js/messages_manager.js | 15 ++++++++++++++- app/js/services.js | 5 +++++ 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/app/js/controllers.js b/app/js/controllers.js index 1dfd60b0..0b4ce2a3 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -321,6 +321,10 @@ angular.module('myApp.controllers', ['myApp.i18n']) delete $scope.credentials.phone_code_valid; error.handled = true; break; + case 'PHONE_CODE_EXPIRED': + $scope.editPhone(); + error.handled = true; + break; } }); diff --git a/app/js/lib/mtproto_wrapper.js b/app/js/lib/mtproto_wrapper.js index 8f555ba1..1fecd851 100644 --- a/app/js/lib/mtproto_wrapper.js +++ b/app/js/lib/mtproto_wrapper.js @@ -7,7 +7,7 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto']) -.factory('MtpApiManager', function (Storage, MtpAuthorizer, MtpNetworkerFactory, MtpSingleInstanceService, AppRuntimeManager, ErrorService, qSync, $q, TelegramMeWebService) { +.factory('MtpApiManager', function (Storage, MtpAuthorizer, MtpNetworkerFactory, MtpSingleInstanceService, AppRuntimeManager, ErrorService, qSync, $rootScope, $q, TelegramMeWebService) { var cachedNetworkers = {}, cachedUploadNetworkers = {}, cachedExportPromise = {}, @@ -31,11 +31,13 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto']) } function mtpSetUserAuth (dcID, userAuth) { + var fullUserAuth = angular.extend({dcID: dcID}, userAuth); Storage.set({ dc: dcID, - user_auth: angular.extend({dcID: dcID}, userAuth) + user_auth: fullUserAuth }); telegramMeNotify(true); + $rootScope.$broadcast('user_auth', fullUserAuth); baseDcID = dcID; } @@ -217,6 +219,29 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto']) }); } } + else if (!options.rawError && error.code == 420) { + var waitTime = error.type.match(/^FLOOD_WAIT_(\d+)/)[1] || 10; + if (waitTime > (options.timeout || 60)) { + return rejectPromise(error); + } + setTimeout(function () { + performRequest(cachedNetworker); + }, waitTime * 1000); + } + else if (!options.rawError && error.code == 500) { + var now = tsNow(); + if (options.stopTime) { + if (now >= options.stopTime) { + return rejectPromise(error); + } + } else { + options.stopTime = now + (options.timeout !== undefined ? options.timeout : 10) * 1000; + } + options.waitTime = options.waitTime ? Math.min(60, options.waitTime * 1.5) : 1; + setTimeout(function () { + performRequest(cachedNetworker); + }, options.waitTime * 1000); + } else { rejectPromise(error); } @@ -412,7 +437,8 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto']) }, { dcID: location.dc_id, fileDownload: true, - createNetworker: true + createNetworker: true, + noErrorBox: true }); }); diff --git a/app/js/messages_manager.js b/app/js/messages_manager.js index 546a3eff..0a9e3876 100644 --- a/app/js/messages_manager.js +++ b/app/js/messages_manager.js @@ -187,6 +187,8 @@ angular.module('myApp.services') return channelsLoadPromise = MtpApiManager.invokeApi('channels.getDialogs', { offset: 0, limit: 100 + }, { + timeout: 300 }).then(function (dialogsResult) { AppUsersManager.saveApiUsers(dialogsResult.users); AppChatsManager.saveApiChats(dialogsResult.chats); @@ -206,6 +208,8 @@ angular.module('myApp.services') return MtpApiManager.invokeApi('messages.getDialogs', { offset: offset, limit: limit + }, { + timeout: 300 }).then(function (dialogsResult) { if (!offset) { TelegramMeWebService.setAuthorized(true); @@ -317,6 +321,9 @@ angular.module('myApp.services') offset_id: maxID ? getMessageLocalID(maxID) : 0, add_offset: offset || 0, limit: limit || 0 + }, { + timeout: 300, + noErrorBox: true }); } else { promise = MtpApiManager.invokeApi('messages.getHistory', { @@ -324,7 +331,10 @@ angular.module('myApp.services') offset_id: maxID ? getMessageLocalID(maxID) : 0, add_offset: offset || 0, limit: limit || 0 - }, {noErrorBox: true}); + }, { + timeout: 300, + noErrorBox: true + }); } return promise.then(function (historyResult) { @@ -785,6 +795,9 @@ angular.module('myApp.services') max_date: 0, limit: limit || 20, max_id: maxID || 0 + }, { + timeout: 300, + noErrorBox: true }).then(function (searchResult) { AppUsersManager.saveApiUsers(searchResult.users); AppChatsManager.saveApiChats(searchResult.chats); diff --git a/app/js/services.js b/app/js/services.js index 3c902f0e..ad6c3b75 100755 --- a/app/js/services.js +++ b/app/js/services.js @@ -442,6 +442,11 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) } }); + $rootScope.$on('user_auth', function (e, userAuth) { + myID = userAuth && userAuth.id || 0; + }); + + setInterval(updateUsersStatuses, 60000);