Namespace events

Naming conflict was firing the error handler twice.

// FREEBIE
This commit is contained in:
lilia 2015-07-10 14:29:46 -07:00
parent 6e74ac9e28
commit 20586e2dcc
3 changed files with 22 additions and 22 deletions

View file

@ -43,12 +43,12 @@
function init() { function init() {
if (!textsecure.registration.isDone()) { return; } if (!textsecure.registration.isDone()) { return; }
window.addEventListener('message', onMessageReceived); window.addEventListener('textsecure:message', onMessageReceived);
window.addEventListener('receipt', onDeliveryReceipt); window.addEventListener('textsecure:receipt', onDeliveryReceipt);
window.addEventListener('contact', onContactReceived); window.addEventListener('textsecure:contact', onContactReceived);
window.addEventListener('group', onGroupReceived); window.addEventListener('textsecure:group', onGroupReceived);
window.addEventListener('sent', onSentMessage); window.addEventListener('textsecure:sent', onSentMessage);
window.addEventListener('error', onError); window.addEventListener('textsecure:error', onError);
// initialize the socket and start listening for messages // initialize the socket and start listening for messages
messageReceiver = new textsecure.MessageReceiver(window); messageReceiver = new textsecure.MessageReceiver(window);

View file

@ -39500,7 +39500,7 @@ function generateKeys(count, progressCallback) {
if (e.code === 1006) { if (e.code === 1006) {
// possible 403. Make an request to confirm // possible 403. Make an request to confirm
TextSecureServer.getDevices(textsecure.storage.user.getNumber()).catch(function(e) { TextSecureServer.getDevices(textsecure.storage.user.getNumber()).catch(function(e) {
var ev = new Event('error'); var ev = new Event('textsecure:error');
ev.error = e; ev.error = e;
eventTarget.dispatchEvent(ev); eventTarget.dispatchEvent(ev);
}); });
@ -39532,7 +39532,7 @@ function generateKeys(count, progressCallback) {
}.bind(this)).catch(function(e) { }.bind(this)).catch(function(e) {
request.respond(500, 'Bad encrypted websocket message'); request.respond(500, 'Bad encrypted websocket message');
console.log("Error handling incoming message:", e); console.log("Error handling incoming message:", e);
var ev = new Event('error'); var ev = new Event('textsecure:error');
ev.error = e; ev.error = e;
this.target.dispatchEvent(ev); this.target.dispatchEvent(ev);
}.bind(this)); }.bind(this));
@ -39545,7 +39545,7 @@ function generateKeys(count, progressCallback) {
} }
}, },
onDeliveryReceipt: function (envelope) { onDeliveryReceipt: function (envelope) {
var ev = new Event('receipt'); var ev = new Event('textsecure:receipt');
ev.proto = envelope; ev.proto = envelope;
this.target.dispatchEvent(ev); this.target.dispatchEvent(ev);
}, },
@ -39556,7 +39556,7 @@ function generateKeys(count, progressCallback) {
envelope.type, envelope.type,
ciphertext ciphertext
).catch(function(error) { ).catch(function(error) {
var ev = new Event('error'); var ev = new Event('textsecure:error');
ev.error = error; ev.error = error;
ev.proto = envelope; ev.proto = envelope;
this.target.dispatchEvent(ev); this.target.dispatchEvent(ev);
@ -39566,7 +39566,7 @@ function generateKeys(count, progressCallback) {
handleSentMessage: function(destination, timestamp, message) { handleSentMessage: function(destination, timestamp, message) {
var source = textsecure.storage.user.getNumber(); var source = textsecure.storage.user.getNumber();
return processDecrypted(message, source).then(function(message) { return processDecrypted(message, source).then(function(message) {
var ev = new Event('sent'); var ev = new Event('textsecure:sent');
ev.data = { ev.data = {
destination : destination, destination : destination,
timestamp : timestamp.toNumber(), timestamp : timestamp.toNumber(),
@ -39581,7 +39581,7 @@ function generateKeys(count, progressCallback) {
close_session(); close_session();
} }
return processDecrypted(message, envelope.source).then(function(message) { return processDecrypted(message, envelope.source).then(function(message) {
var ev = new Event('message'); var ev = new Event('textsecure:message');
ev.data = { ev.data = {
source : envelope.source, source : envelope.source,
timestamp : envelope.timestamp.toNumber(), timestamp : envelope.timestamp.toNumber(),
@ -39641,7 +39641,7 @@ function generateKeys(count, progressCallback) {
var contactBuffer = new ContactBuffer(attachmentPointer.data); var contactBuffer = new ContactBuffer(attachmentPointer.data);
var contactDetails = contactBuffer.next(); var contactDetails = contactBuffer.next();
while (contactDetails !== undefined) { while (contactDetails !== undefined) {
var ev = new Event('contact'); var ev = new Event('textsecure:contact');
ev.contactDetails = contactDetails; ev.contactDetails = contactDetails;
eventTarget.dispatchEvent(ev); eventTarget.dispatchEvent(ev);
contactDetails = contactBuffer.next(); contactDetails = contactBuffer.next();
@ -39669,7 +39669,7 @@ function generateKeys(count, progressCallback) {
); );
} }
}).then(function() { }).then(function() {
var ev = new Event('group'); var ev = new Event('textsecure:group');
ev.groupDetails = groupDetails; ev.groupDetails = groupDetails;
eventTarget.dispatchEvent(ev); eventTarget.dispatchEvent(ev);
}); });

View file

@ -37,7 +37,7 @@
if (e.code === 1006) { if (e.code === 1006) {
// possible 403. Make an request to confirm // possible 403. Make an request to confirm
TextSecureServer.getDevices(textsecure.storage.user.getNumber()).catch(function(e) { TextSecureServer.getDevices(textsecure.storage.user.getNumber()).catch(function(e) {
var ev = new Event('error'); var ev = new Event('textsecure:error');
ev.error = e; ev.error = e;
eventTarget.dispatchEvent(ev); eventTarget.dispatchEvent(ev);
}); });
@ -69,7 +69,7 @@
}.bind(this)).catch(function(e) { }.bind(this)).catch(function(e) {
request.respond(500, 'Bad encrypted websocket message'); request.respond(500, 'Bad encrypted websocket message');
console.log("Error handling incoming message:", e); console.log("Error handling incoming message:", e);
var ev = new Event('error'); var ev = new Event('textsecure:error');
ev.error = e; ev.error = e;
this.target.dispatchEvent(ev); this.target.dispatchEvent(ev);
}.bind(this)); }.bind(this));
@ -82,7 +82,7 @@
} }
}, },
onDeliveryReceipt: function (envelope) { onDeliveryReceipt: function (envelope) {
var ev = new Event('receipt'); var ev = new Event('textsecure:receipt');
ev.proto = envelope; ev.proto = envelope;
this.target.dispatchEvent(ev); this.target.dispatchEvent(ev);
}, },
@ -93,7 +93,7 @@
envelope.type, envelope.type,
ciphertext ciphertext
).catch(function(error) { ).catch(function(error) {
var ev = new Event('error'); var ev = new Event('textsecure:error');
ev.error = error; ev.error = error;
ev.proto = envelope; ev.proto = envelope;
this.target.dispatchEvent(ev); this.target.dispatchEvent(ev);
@ -103,7 +103,7 @@
handleSentMessage: function(destination, timestamp, message) { handleSentMessage: function(destination, timestamp, message) {
var source = textsecure.storage.user.getNumber(); var source = textsecure.storage.user.getNumber();
return processDecrypted(message, source).then(function(message) { return processDecrypted(message, source).then(function(message) {
var ev = new Event('sent'); var ev = new Event('textsecure:sent');
ev.data = { ev.data = {
destination : destination, destination : destination,
timestamp : timestamp.toNumber(), timestamp : timestamp.toNumber(),
@ -118,7 +118,7 @@
close_session(); close_session();
} }
return processDecrypted(message, envelope.source).then(function(message) { return processDecrypted(message, envelope.source).then(function(message) {
var ev = new Event('message'); var ev = new Event('textsecure:message');
ev.data = { ev.data = {
source : envelope.source, source : envelope.source,
timestamp : envelope.timestamp.toNumber(), timestamp : envelope.timestamp.toNumber(),
@ -178,7 +178,7 @@
var contactBuffer = new ContactBuffer(attachmentPointer.data); var contactBuffer = new ContactBuffer(attachmentPointer.data);
var contactDetails = contactBuffer.next(); var contactDetails = contactBuffer.next();
while (contactDetails !== undefined) { while (contactDetails !== undefined) {
var ev = new Event('contact'); var ev = new Event('textsecure:contact');
ev.contactDetails = contactDetails; ev.contactDetails = contactDetails;
eventTarget.dispatchEvent(ev); eventTarget.dispatchEvent(ev);
contactDetails = contactBuffer.next(); contactDetails = contactBuffer.next();
@ -206,7 +206,7 @@
); );
} }
}).then(function() { }).then(function() {
var ev = new Event('group'); var ev = new Event('textsecure:group');
ev.groupDetails = groupDetails; ev.groupDetails = groupDetails;
eventTarget.dispatchEvent(ev); eventTarget.dispatchEvent(ev);
}); });