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; }
},
sendMessage: function(message, attachments) {
sendMessage: function(body, attachments) {
var now = Date.now();
this.messageCollection.add({
body : message,
var message = this.messageCollection.add({
body : body,
conversationId : this.id,
type : 'outgoing',
attachments : attachments,
sent_at : now,
received_at : now
}).save();
});
message.save();
this.save({
unreadCount : 0,
active_at : now
});
var sendFunc;
if (this.get('type') == 'private') {
return textsecure.messaging.sendMessageToNumber(this.get('id'), message, attachments);
sendFunc = textsecure.messaging.sendMessageToNumber;
}
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) {

View file

@ -114,12 +114,25 @@ window.textsecure.messaging = function() {
return Promise.all(promises);
}
var tryMessageAgain = function(number, encodedMessage, callback) {
//TODO: Wipe identity key!
refreshGroups(number).then(function() {
var message = textsecure.protobuf.PushMessageContent.decode(encodedMessage);
textsecure.sendMessageProto([number], message, callback);
});
var tryMessageAgain = function(number, encodedMessage, message_id) {
var message = new Whisper.MessageCollection().add({id: message_id});
message.fetch().then(function() {
textsecure.storage.removeEncrypted("devices" + number);
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);
@ -175,7 +188,7 @@ window.textsecure.messaging = function() {
if (error.message !== "Identity key changed")
registerError(number, "Failed to reload device keys", error);
else {
error = new textsecure.OutgoingIdentityKeyError(encodedNumber, message.encode());
error = new textsecure.OutgoingIdentityKeyError(number, getString(message.encode()));
registerError(number, "Identity key changed", error);
}
});