From 06601f50d5a0fad0d91d7019187c4484d4c7eaf6 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Fri, 11 Apr 2014 08:50:20 -0400 Subject: [PATCH] Improved mtproto errors handling --- app/js/lib/mtproto.js | 17 ++++++++++++----- app/partials/error_modal.html | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/js/lib/mtproto.js b/app/js/lib/mtproto.js index e353d8c8..6cbc7904 100644 --- a/app/js/lib/mtproto.js +++ b/app/js/lib/mtproto.js @@ -967,10 +967,12 @@ TLDeserialization.prototype.fetchObject = function (type, field) { predicate = constructorData.predicate; var result = {'_': predicate}, + overrideKey = (this.mtproto ? 'mt_' : '') + predicate, self = this; - if (this.override[predicate]) { - this.override[predicate].apply(this, [result, field + '[' + predicate + ']']); + + if (this.override[overrideKey]) { + this.override[overrideKey].apply(this, [result, field + '[' + predicate + ']']); } else { angular.forEach(constructorData.params, function (param) { result[param.name] = self.fetchObject(param.type, field + '[' + predicate + '][' + param.name + ']'); @@ -2227,7 +2229,7 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato var deserializerOptions = { mtproto: true, override: { - message: function (result, field) { + mt_message: function (result, field) { result.msg_id = this.fetchLong(field + '[msg_id]'); result.seqno = this.fetchInt(field + '[seqno]'); result.bytes = this.fetchInt(field + '[bytes]'); @@ -2237,12 +2239,17 @@ factory('MtpNetworkerFactory', function (MtpDcConfigurator, MtpMessageIdGenerato try { result.body = this.fetchObject('Object', field + '[body]'); } catch (e) { + console.error(dT(), 'parse error', e.message, e.stack); result.body = {_: 'parse_error', error: e}; } - this.offset = offset + result.bytes; + if (this.offset != offset + result.bytes) { + console.warn(dT(), 'set offset', this.offset, offset, result.bytes); + console.log(dT(), result); + this.offset = offset + result.bytes; + } // console.log(dT(), 'override message', result); }, - rpc_result: function (result, field) { + mt_rpc_result: function (result, field) { result.req_msg_id = this.fetchLong(field + '[req_msg_id]'); var sentMessage = self.sentMessages[result.req_msg_id], diff --git a/app/partials/error_modal.html b/app/partials/error_modal.html index c9f1b010..58988646 100644 --- a/app/partials/error_modal.html +++ b/app/partials/error_modal.html @@ -57,7 +57,7 @@
Technical details here