Consistent returns, no more eventTarget, comments for tricky bits

FREEBIE
pull/749/head
Scott Nonnenberg 8 years ago
parent 8c231d9830
commit 73a77c7b97

@ -56,12 +56,12 @@ MessageReceiver.prototype.extend({
return; return;
} }
// possible 403 or network issue. Make an request to confirm // possible 403 or network issue. Make an request to confirm
this.server.getDevices(this.number) return this.server.getDevices(this.number)
.then(this.connect.bind(this)) // No HTTP error? Reconnect .then(this.connect.bind(this)) // No HTTP error? Reconnect
.catch(function(e) { .catch(function(e) {
var ev = new Event('error'); var ev = new Event('error');
ev.error = e; ev.error = e;
this.dispatchAndWait(ev); return this.dispatchAndWait(ev);
}.bind(this)); }.bind(this));
}, },
handleRequest: function(request) { handleRequest: function(request) {
@ -134,14 +134,17 @@ MessageReceiver.prototype.extend({
return this.dispatchAndWait(ev); return this.dispatchAndWait(ev);
}.bind(this); }.bind(this);
var scheduleDispatch = function() { var queueDispatch = function() {
// resetting count to zero so everything queued after this starts over again // resetting count to zero so everything queued after this starts over again
this.count = 0; this.count = 0;
this.addToQueue(dispatchEmpty); this.addToQueue(dispatchEmpty);
}.bind(this); }.bind(this);
Promise.all(incoming).then(scheduleDispatch, scheduleDispatch); // We first wait for all recently-received messages (this.incoming) to be queued,
// then we add a task to emit the 'empty' event to the queue, so all message
// processing is complete by the time it runs.
Promise.all(incoming).then(queueDispatch, queueDispatch);
}, },
updateProgress: function(count) { updateProgress: function(count) {
// count by 10s // count by 10s
@ -529,7 +532,6 @@ MessageReceiver.prototype.extend({
}, },
handleContacts: function(envelope, contacts) { handleContacts: function(envelope, contacts) {
console.log('contact sync'); console.log('contact sync');
var eventTarget = this;
var attachmentPointer = contacts.blob; var attachmentPointer = contacts.blob;
return this.handleAttachment(attachmentPointer).then(function() { return this.handleAttachment(attachmentPointer).then(function() {
var results = []; var results = [];
@ -539,7 +541,7 @@ MessageReceiver.prototype.extend({
var ev = new Event('contact'); var ev = new Event('contact');
ev.confirm = this.removeFromCache.bind(this, envelope); ev.confirm = this.removeFromCache.bind(this, envelope);
ev.contactDetails = contactDetails; ev.contactDetails = contactDetails;
results.push(eventTarget.dispatchAndWait(ev)); results.push(this.dispatchAndWait(ev));
if (contactDetails.verified) { if (contactDetails.verified) {
results.push(this.handleVerified( results.push(this.handleVerified(
@ -554,7 +556,7 @@ MessageReceiver.prototype.extend({
var ev = new Event('contactsync'); var ev = new Event('contactsync');
ev.confirm = this.removeFromCache.bind(this, envelope); ev.confirm = this.removeFromCache.bind(this, envelope);
results.push(eventTarget.dispatchAndWait(ev)); results.push(this.dispatchAndWait(ev));
return Promise.all(results); return Promise.all(results);
}.bind(this)); }.bind(this));

Loading…
Cancel
Save