Fixup OutgoingIdentityKeyError handling

This commit is contained in:
lilia 2014-12-20 00:36:44 -08:00
parent 3795ea5070
commit 348b5a53b1
2 changed files with 38 additions and 13 deletions

View file

@ -42,28 +42,40 @@
if (missing.length) { return "Conversation must have " + missing; } if (missing.length) { return "Conversation must have " + missing; }
}, },
sendMessage: function(message, attachments) { sendMessage: function(body, attachments) {
var now = Date.now(); var now = Date.now();
this.messageCollection.add({ var message = this.messageCollection.add({
body : message, body : body,
conversationId : this.id, conversationId : this.id,
type : 'outgoing', type : 'outgoing',
attachments : attachments, attachments : attachments,
sent_at : now, sent_at : now,
received_at : now received_at : now
}).save(); });
message.save();
this.save({ this.save({
unreadCount : 0, unreadCount : 0,
active_at : now active_at : now
}); });
var sendFunc;
if (this.get('type') == 'private') { if (this.get('type') == 'private') {
return textsecure.messaging.sendMessageToNumber(this.get('id'), message, attachments); sendFunc = textsecure.messaging.sendMessageToNumber;
} }
else { else {
return textsecure.messaging.sendMessageToGroup(this.get('groupId'), message, attachments); sendFunc = textsecure.messaging.sendMessageToGroup;
} }
sendFunc(this.get('id'), body, attachments).catch(function(e) {
if (e.name === 'OutgoingIdentityKeyError') {
e.args.push(message.id);
message.save({ errors : [e] }).then(function() {
extension.trigger('message', message); // notify frontend listeners
});
} else {
throw e;
}
});
}, },
receiveMessage: function(decrypted) { receiveMessage: function(decrypted) {

View file

@ -114,12 +114,25 @@ window.textsecure.messaging = function() {
return Promise.all(promises); return Promise.all(promises);
} }
var tryMessageAgain = function(number, encodedMessage, callback) { var tryMessageAgain = function(number, encodedMessage, message_id) {
//TODO: Wipe identity key! var message = new Whisper.MessageCollection().add({id: message_id});
refreshGroups(number).then(function() { message.fetch().then(function() {
var message = textsecure.protobuf.PushMessageContent.decode(encodedMessage); textsecure.storage.removeEncrypted("devices" + number);
textsecure.sendMessageProto([number], message, callback); refreshGroups(number).then(function() {
}); var proto = textsecure.protobuf.PushMessageContent.decode(encodedMessage, 'binary');
sendMessageProto([number], proto, function(res) {
if (res.failure.length > 0) {
message.set('errors', []);
}
else {
message.set('errors', res.failures);
}
message.save().then(function(){
extension.trigger('message', message); // notify frontend listeners
});
});
});
});
}; };
textsecure.replay.registerFunction(tryMessageAgain, textsecure.replay.Type.SEND_MESSAGE); textsecure.replay.registerFunction(tryMessageAgain, textsecure.replay.Type.SEND_MESSAGE);
@ -175,7 +188,7 @@ window.textsecure.messaging = function() {
if (error.message !== "Identity key changed") if (error.message !== "Identity key changed")
registerError(number, "Failed to reload device keys", error); registerError(number, "Failed to reload device keys", error);
else { else {
error = new textsecure.OutgoingIdentityKeyError(encodedNumber, message.encode()); error = new textsecure.OutgoingIdentityKeyError(number, getString(message.encode()));
registerError(number, "Identity key changed", error); registerError(number, "Identity key changed", error);
} }
}); });