This commit is contained in:
Igor Zhukov 2015-11-02 13:44:05 +03:00
parent ce394102c2
commit de9b7e2b95
4 changed files with 52 additions and 4 deletions

View File

@ -321,6 +321,10 @@ angular.module('myApp.controllers', ['myApp.i18n'])
delete $scope.credentials.phone_code_valid; delete $scope.credentials.phone_code_valid;
error.handled = true; error.handled = true;
break; break;
case 'PHONE_CODE_EXPIRED':
$scope.editPhone();
error.handled = true;
break;
} }
}); });

View File

@ -7,7 +7,7 @@
angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto']) 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 = {}, var cachedNetworkers = {},
cachedUploadNetworkers = {}, cachedUploadNetworkers = {},
cachedExportPromise = {}, cachedExportPromise = {},
@ -31,11 +31,13 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto'])
} }
function mtpSetUserAuth (dcID, userAuth) { function mtpSetUserAuth (dcID, userAuth) {
var fullUserAuth = angular.extend({dcID: dcID}, userAuth);
Storage.set({ Storage.set({
dc: dcID, dc: dcID,
user_auth: angular.extend({dcID: dcID}, userAuth) user_auth: fullUserAuth
}); });
telegramMeNotify(true); telegramMeNotify(true);
$rootScope.$broadcast('user_auth', fullUserAuth);
baseDcID = dcID; 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 { else {
rejectPromise(error); rejectPromise(error);
} }
@ -412,7 +437,8 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto'])
}, { }, {
dcID: location.dc_id, dcID: location.dc_id,
fileDownload: true, fileDownload: true,
createNetworker: true createNetworker: true,
noErrorBox: true
}); });
}); });

View File

@ -187,6 +187,8 @@ angular.module('myApp.services')
return channelsLoadPromise = MtpApiManager.invokeApi('channels.getDialogs', { return channelsLoadPromise = MtpApiManager.invokeApi('channels.getDialogs', {
offset: 0, offset: 0,
limit: 100 limit: 100
}, {
timeout: 300
}).then(function (dialogsResult) { }).then(function (dialogsResult) {
AppUsersManager.saveApiUsers(dialogsResult.users); AppUsersManager.saveApiUsers(dialogsResult.users);
AppChatsManager.saveApiChats(dialogsResult.chats); AppChatsManager.saveApiChats(dialogsResult.chats);
@ -206,6 +208,8 @@ angular.module('myApp.services')
return MtpApiManager.invokeApi('messages.getDialogs', { return MtpApiManager.invokeApi('messages.getDialogs', {
offset: offset, offset: offset,
limit: limit limit: limit
}, {
timeout: 300
}).then(function (dialogsResult) { }).then(function (dialogsResult) {
if (!offset) { if (!offset) {
TelegramMeWebService.setAuthorized(true); TelegramMeWebService.setAuthorized(true);
@ -317,6 +321,9 @@ angular.module('myApp.services')
offset_id: maxID ? getMessageLocalID(maxID) : 0, offset_id: maxID ? getMessageLocalID(maxID) : 0,
add_offset: offset || 0, add_offset: offset || 0,
limit: limit || 0 limit: limit || 0
}, {
timeout: 300,
noErrorBox: true
}); });
} else { } else {
promise = MtpApiManager.invokeApi('messages.getHistory', { promise = MtpApiManager.invokeApi('messages.getHistory', {
@ -324,7 +331,10 @@ angular.module('myApp.services')
offset_id: maxID ? getMessageLocalID(maxID) : 0, offset_id: maxID ? getMessageLocalID(maxID) : 0,
add_offset: offset || 0, add_offset: offset || 0,
limit: limit || 0 limit: limit || 0
}, {noErrorBox: true}); }, {
timeout: 300,
noErrorBox: true
});
} }
return promise.then(function (historyResult) { return promise.then(function (historyResult) {
@ -785,6 +795,9 @@ angular.module('myApp.services')
max_date: 0, max_date: 0,
limit: limit || 20, limit: limit || 20,
max_id: maxID || 0 max_id: maxID || 0
}, {
timeout: 300,
noErrorBox: true
}).then(function (searchResult) { }).then(function (searchResult) {
AppUsersManager.saveApiUsers(searchResult.users); AppUsersManager.saveApiUsers(searchResult.users);
AppChatsManager.saveApiChats(searchResult.chats); AppChatsManager.saveApiChats(searchResult.chats);

View File

@ -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); setInterval(updateUsersStatuses, 60000);