Read/Delivery Receipts: Wait for resolution in main queue

FREEBIE
This commit is contained in:
Scott Nonnenberg 2017-08-03 18:10:45 -07:00
parent 92ba295d52
commit 7faf83bc01
3 changed files with 23 additions and 20 deletions

View file

@ -381,6 +381,9 @@
});
receipt.on('remove', ev.confirm);
// Calling this directly so we can wait for completion
return Whisper.ReadReceipts.onReceipt(receipt);
}
function onVerified(ev) {
@ -447,6 +450,9 @@
});
receipt.on('remove', ev.confirm);
// Calling this directly so we can wait for completion
return Whisper.DeliveryReceipts.onReceipt(receipt);
}
window.owsDesktopApp = {

View file

@ -6,9 +6,6 @@
window.Whisper = window.Whisper || {};
Whisper.DeliveryReceipts = new (Backbone.Collection.extend({
initialize: function() {
this.on('add', this.onReceipt);
},
forMessage: function(conversation, message) {
var recipients;
if (conversation.isPrivate()) {
@ -25,7 +22,7 @@
},
onReceipt: function(receipt) {
var messages = new Whisper.MessageCollection();
messages.fetchSentAt(receipt.get('timestamp')).then(function() {
return messages.fetchSentAt(receipt.get('timestamp')).then(function() {
if (messages.length === 0) { return; }
var message = messages.find(function(message) {
return (!message.isIncoming() && receipt.get('source') === message.get('conversationId'));
@ -44,18 +41,21 @@
}).then(function(message) {
if (message) {
var deliveries = message.get('delivered') || 0;
message.save({
delivered: deliveries + 1
}).then(function() {
// notify frontend listeners
var conversation = ConversationController.get(
message.get('conversationId')
);
if (conversation) {
conversation.trigger('delivered', message);
}
return new Promise(function(resolve, reject) {
message.save({
delivered: deliveries + 1
}).then(function() {
// notify frontend listeners
var conversation = ConversationController.get(
message.get('conversationId')
);
if (conversation) {
conversation.trigger('delivered', message);
}
this.remove(receipt);
this.remove(receipt);
resolve();
}.bind(this), reject);
}.bind(this));
// TODO: consider keeping a list of numbers we've
// successfully delivered to?

View file

@ -5,9 +5,6 @@
'use strict';
window.Whisper = window.Whisper || {};
Whisper.ReadReceipts = new (Backbone.Collection.extend({
initialize: function() {
this.on('add', this.onReceipt);
},
forMessage: function(message) {
var receipt = this.findWhere({
sender: message.get('source'),
@ -21,13 +18,13 @@
},
onReceipt: function(receipt) {
var messages = new Whisper.MessageCollection();
messages.fetchSentAt(receipt.get('timestamp')).then(function() {
return messages.fetchSentAt(receipt.get('timestamp')).then(function() {
var message = messages.find(function(message) {
return (message.isIncoming() && message.isUnread() &&
message.get('source') === receipt.get('sender'));
});
if (message) {
message.markRead(receipt.get('read_at')).then(function() {
return message.markRead(receipt.get('read_at')).then(function() {
this.notifyConversation(message);
this.remove(receipt);
}.bind(this));