diff --git a/js/background.js b/js/background.js index b933c8374fca..ef5479c8b450 100644 --- a/js/background.js +++ b/js/background.js @@ -302,18 +302,18 @@ } function onError(ev) { - var e = ev.error; - console.log(e); - console.log(e.stack); + var error = ev.error; + console.log(error); + console.log(error.stack); - if (e.name === 'HTTPError' && (e.code == 401 || e.code == 403)) { + if (error.name === 'HTTPError' && (error.code == 401 || error.code == 403)) { Whisper.Registration.remove(); Whisper.events.trigger('unauthorized'); extension.install(); return; } - if (e.name === 'HTTPError' && e.code == -1) { + if (error.name === 'HTTPError' && error.code == -1) { // Failed to connect to server if (navigator.onLine) { console.log('retrying in 1 minute'); @@ -329,7 +329,10 @@ } if (ev.proto) { - if (e.name === 'MessageCounterError') { + if (error.name === 'MessageCounterError') { + if (ev.confirm) { + ev.confirm(); + } // Ignore this message. It is likely a duplicate delivery // because the server lost our ack the first time. return; @@ -337,7 +340,7 @@ var envelope = ev.proto; var message = initIncomingMessage(envelope); - return message.saveErrors(e).then(function() { + return message.saveErrors(error).then(function() { var id = message.get('conversationId'); return ConversationController.findOrCreateById(id, 'private').then(function(conversation) { conversation.set({ @@ -356,6 +359,10 @@ conversation.notify(message); } + if (ev.confirm) { + ev.confirm(); + } + return new Promise(function(resolve, reject) { conversation.save().then(resolve, reject); }); @@ -363,7 +370,7 @@ }); } - throw e; + throw error; } function onReadReceipt(ev) { diff --git a/js/libtextsecure.js b/js/libtextsecure.js index bb2cf65fb648..4dcc54be17ab 100644 --- a/js/libtextsecure.js +++ b/js/libtextsecure.js @@ -38631,6 +38631,7 @@ MessageReceiver.prototype.extend({ var ev = new Event('error'); ev.error = error; ev.proto = envelope; + ev.confirm = this.removeFromCache.bind(this, envelope); var returnError = function() { return Promise.reject(error); diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index e70eea0e8b3f..0059f2053ae5 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -380,6 +380,7 @@ MessageReceiver.prototype.extend({ var ev = new Event('error'); ev.error = error; ev.proto = envelope; + ev.confirm = this.removeFromCache.bind(this, envelope); var returnError = function() { return Promise.reject(error);