Browse Source

Correct log out from all DCs

master
Igor Zhukov 10 years ago
parent
commit
f607fdf72e
  1. 29
      app/js/lib/mtproto_wrapper.js

29
app/js/lib/mtproto_wrapper.js

@ -31,17 +31,26 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto'])
} }
function mtpLogOut () { function mtpLogOut () {
return mtpInvokeApi('auth.logOut').then(function () { var storageKeys = [];
Storage.remove('dc', 'user_auth'); for (var dcID = 1; dcID <= 5; dcID++) {
storageKeys.push('dc' + dcID + '_auth_key');
baseDcID = false; }
}, function (error) { return Storage.get.apply(Storage, storageKeys).then(function (storageResult) {
Storage.remove('dc', 'user_auth'); var logoutPromises = [];
if (error && error.code != 401) { for (var i = 0; i < storageResult.length; i++) {
Storage.remove('dc' + baseDcID + '_auth_key'); if (storageResult[i]) {
logoutPromises.push(mtpInvokeApi('auth.logOut', {}, {dcID: i + 1}));
}
} }
baseDcID = false; return $q.all(logoutPromises).then(function () {
error.handled = true; Storage.remove('dc', 'user_auth');
baseDcID = false;
}, function (error) {
Storage.remove.apply(storageKeys);
Storage.remove('dc', 'user_auth');
baseDcID = false;
error.handled = true;
});
}); });
} }

Loading…
Cancel
Save