From b6025330840c421f42297b78fa14af8962d90d11 Mon Sep 17 00:00:00 2001 From: lilia Date: Tue, 16 Feb 2016 17:46:20 -0800 Subject: [PATCH] Serialize calls to sendSyncMessage Fixes #679 // FREEBIE --- js/models/messages.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/js/models/messages.js b/js/models/messages.js index 9dcfd381..f29a4f2e 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -167,15 +167,17 @@ }, sendSyncMessage: function() { - var dataMessage = this.get('dataMessage'); - if (this.get('synced') || !dataMessage) { - return; - } - - textsecure.messaging.sendSyncMessage( - dataMessage, this.get('sent_at'), this.get('destination') - ).then(function() { - this.save({synced: true, dataMessage: null}); + this.syncPromise = this.syncPromise || Promise.resolve(); + this.syncPromise = this.syncPromise.then(function() { + var dataMessage = this.get('dataMessage'); + if (this.get('synced') || !dataMessage) { + return; + } + return textsecure.messaging.sendSyncMessage( + dataMessage, this.get('sent_at'), this.get('destination') + ).then(function() { + this.save({synced: true, dataMessage: null}); + }.bind(this)); }.bind(this)); },