|
|
@ -351,7 +351,7 @@ function TLSerialization (options) { |
|
|
|
|
|
|
|
|
|
|
|
this.createBuffer(); |
|
|
|
this.createBuffer(); |
|
|
|
|
|
|
|
|
|
|
|
this.debug = options.debug !== undefined ? options.debug : window._debugMode; |
|
|
|
// this.debug = options.debug !== undefined ? options.debug : window._debugMode;
|
|
|
|
this.mtproto = options.mtproto || false; |
|
|
|
this.mtproto = options.mtproto || false; |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
@ -631,7 +631,7 @@ function TLDeserialization (buffer, options) { |
|
|
|
this.intView = new Uint32Array(this.buffer); |
|
|
|
this.intView = new Uint32Array(this.buffer); |
|
|
|
this.byteView = new Uint8Array(this.buffer); |
|
|
|
this.byteView = new Uint8Array(this.buffer); |
|
|
|
|
|
|
|
|
|
|
|
this.debug = options.debug !== undefined ? options.debug : window._debugMode; |
|
|
|
// this.debug = options.debug !== undefined ? options.debug : window._debugMode;
|
|
|
|
this.mtproto = options.mtproto || false; |
|
|
|
this.mtproto = options.mtproto || false; |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
@ -1021,7 +1021,7 @@ factory('MtpMessageIdGenerator', function (AppConfigManager) { |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
function generateMessageID () { |
|
|
|
function generateMessageID () { |
|
|
|
var timeTicks = +new Date() + timeOffset, |
|
|
|
var timeTicks = +new Date() + (timeOffset * 1000), |
|
|
|
timeSec = Math.floor(timeTicks / 1000), |
|
|
|
timeSec = Math.floor(timeTicks / 1000), |
|
|
|
timeMSec = timeTicks % 1000, |
|
|
|
timeMSec = timeTicks % 1000, |
|
|
|
random = nextRandomInt(0xFFFF); |
|
|
|
random = nextRandomInt(0xFFFF); |
|
|
@ -1042,6 +1042,7 @@ factory('MtpMessageIdGenerator', function (AppConfigManager) { |
|
|
|
|
|
|
|
|
|
|
|
function applyServerTime (serverTime, localTime) { |
|
|
|
function applyServerTime (serverTime, localTime) { |
|
|
|
timeOffset = serverTime - Math.floor((localTime || +new Date()) / 1000); |
|
|
|
timeOffset = serverTime - Math.floor((localTime || +new Date()) / 1000); |
|
|
|
|
|
|
|
dLog('Apply server time', serverTime, localTime, timeOffset); |
|
|
|
AppConfigManager.set({server_time_offset: timeOffset}); |
|
|
|
AppConfigManager.set({server_time_offset: timeOffset}); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -1787,7 +1788,9 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato |
|
|
|
|
|
|
|
|
|
|
|
this.sentMessages[message.msg_id] = containerSentMessage; |
|
|
|
this.sentMessages[message.msg_id] = containerSentMessage; |
|
|
|
|
|
|
|
|
|
|
|
// dLog('Container', innerMessages, message.msg_id, message.seq_no);
|
|
|
|
if (window._debugMode) { |
|
|
|
|
|
|
|
dLog('Container', innerMessages, message.msg_id, message.seq_no); |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (message.noResponse) { |
|
|
|
if (message.noResponse) { |
|
|
|
noResponseMsgs.push(message.msg_id); |
|
|
|
noResponseMsgs.push(message.msg_id); |
|
|
@ -2035,7 +2038,7 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'bad_server_salt': |
|
|
|
case 'bad_server_salt': |
|
|
|
dLog('bad server salt', message); |
|
|
|
dLog('Bad server salt', message); |
|
|
|
var sentMsg = this.sentMessages[message.bad_msg_id]; |
|
|
|
var sentMsg = this.sentMessages[message.bad_msg_id]; |
|
|
|
if (!sentMsg || sentMsg.seq_no != message.bad_msg_seqno) { |
|
|
|
if (!sentMsg || sentMsg.seq_no != message.bad_msg_seqno) { |
|
|
|
dLog(message.bad_msg_id, message.bad_msg_seqno); |
|
|
|
dLog(message.bad_msg_id, message.bad_msg_seqno); |
|
|
@ -2047,6 +2050,21 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato |
|
|
|
this.ackMessage(messageID); |
|
|
|
this.ackMessage(messageID); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 'bad_msg_notification': |
|
|
|
|
|
|
|
dLog('Bad msg notification', message); |
|
|
|
|
|
|
|
var sentMsg = this.sentMessages[message.bad_msg_id]; |
|
|
|
|
|
|
|
if (!sentMsg || sentMsg.seq_no != message.bad_msg_seqno) { |
|
|
|
|
|
|
|
dLog(message.bad_msg_id, message.bad_msg_seqno); |
|
|
|
|
|
|
|
throw new Error('Bad msg notification for invalid message'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (message.error_code == 16 || message.error_code == 17) { |
|
|
|
|
|
|
|
MtpMessageIdGenerator.applyServerTime((new BigInteger(messageID, 10)).shiftRight(32).toString(10)); |
|
|
|
|
|
|
|
this.pushResend(message.bad_msg_id); |
|
|
|
|
|
|
|
this.ackMessage(messageID); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case 'message': |
|
|
|
case 'message': |
|
|
|
this.serverMessages.push(message.msg_id); |
|
|
|
this.serverMessages.push(message.msg_id); |
|
|
|
this.processMessage(message.body, message.msg_id, sessionID); |
|
|
|
this.processMessage(message.body, message.msg_id, sessionID); |
|
|
@ -2439,7 +2457,7 @@ factory('MtpApiFileManager', function (MtpApiManager, $q, $window) { |
|
|
|
cacheFileWriter, |
|
|
|
cacheFileWriter, |
|
|
|
errorHandler = function (error) { |
|
|
|
errorHandler = function (error) { |
|
|
|
deferred.reject(error); |
|
|
|
deferred.reject(error); |
|
|
|
if (cacheFileWriter) cacheFileWriter.truncate(); |
|
|
|
if (cacheFileWriter) cacheFileWriter.truncate(0); |
|
|
|
errorHandler = angular.noop; |
|
|
|
errorHandler = angular.noop; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -2474,7 +2492,7 @@ factory('MtpApiFileManager', function (MtpApiManager, $q, $window) { |
|
|
|
cacheFileWriter, |
|
|
|
cacheFileWriter, |
|
|
|
errorHandler = function (error) { |
|
|
|
errorHandler = function (error) { |
|
|
|
deferred.reject(error); |
|
|
|
deferred.reject(error); |
|
|
|
if (cacheFileWriter) cacheFileWriter.truncate(); |
|
|
|
if (cacheFileWriter) cacheFileWriter.truncate(0); |
|
|
|
errorHandler = angular.noop; |
|
|
|
errorHandler = angular.noop; |
|
|
|
}, |
|
|
|
}, |
|
|
|
doDownload = function () { |
|
|
|
doDownload = function () { |
|
|
@ -2543,7 +2561,7 @@ factory('MtpApiFileManager', function (MtpApiManager, $q, $window) { |
|
|
|
console.error(error); |
|
|
|
console.error(error); |
|
|
|
// dLog('fail');
|
|
|
|
// dLog('fail');
|
|
|
|
deferred.reject(error); |
|
|
|
deferred.reject(error); |
|
|
|
if (cacheFileWriter) cacheFileWriter.truncate(); |
|
|
|
if (cacheFileWriter) cacheFileWriter.truncate(0); |
|
|
|
errorHandler = angular.noop; |
|
|
|
errorHandler = angular.noop; |
|
|
|
}, |
|
|
|
}, |
|
|
|
saveToFileEntry = function (fileEntry) { |
|
|
|
saveToFileEntry = function (fileEntry) { |
|
|
@ -2685,7 +2703,7 @@ factory('MtpApiFileManager', function (MtpApiManager, $q, $window) { |
|
|
|
errorHandler = function (error) { |
|
|
|
errorHandler = function (error) { |
|
|
|
dLog('fail'); |
|
|
|
dLog('fail'); |
|
|
|
deferred.reject(error); |
|
|
|
deferred.reject(error); |
|
|
|
if (cacheFileWriter) cacheFileWriter.truncate(); |
|
|
|
if (cacheFileWriter) cacheFileWriter.truncate(0); |
|
|
|
errorHandler = angular.noop; |
|
|
|
errorHandler = angular.noop; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|