Let the application layer send sync messages
Previously, libtextsecure would send a sync message automatically when appropriate. This fails if any recipient has a key conflict or if our network connection fails mid-send. Instead, when appropriate, return a the DataMessage encoded as an array buffer for later syncing. This lets the application choose when to send it, which we now do after any successful send to a recipient, rather than after all recipients are successfully sent to. Eventually we should move the DataMessage protobuf construction and group sending logic to the application layer entirely, in which case we wouldn't need libtextsecure to construct the sync message either. Fixes #408
This commit is contained in:
parent
5c37c3d6ce
commit
07702c4ee5
4 changed files with 54 additions and 16 deletions
|
@ -140,13 +140,36 @@
|
|||
|
||||
send: function(promise) {
|
||||
this.trigger('pending');
|
||||
return promise.then(function() {
|
||||
return promise.then(function(result) {
|
||||
this.trigger('done');
|
||||
if (result.dataMessage) {
|
||||
this.set({dataMessage: result.dataMessage});
|
||||
}
|
||||
this.save({sent: true});
|
||||
}.bind(this)).catch(function(errors) {
|
||||
this.sendSyncMessage();
|
||||
}.bind(this)).catch(function(result) {
|
||||
this.trigger('done');
|
||||
if (result.dataMessage) {
|
||||
this.set({dataMessage: result.dataMessage});
|
||||
}
|
||||
this.set({sent: true});
|
||||
this.saveErrors(result.errors);
|
||||
if (result.successfulNumbers.length > 0) {
|
||||
this.sendSyncMessage();
|
||||
}
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
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});
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue