Read/Delivery Receipts: Wait for resolution in main queue
FREEBIE
This commit is contained in:
parent
92ba295d52
commit
7faf83bc01
3 changed files with 23 additions and 20 deletions
|
@ -381,6 +381,9 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
receipt.on('remove', ev.confirm);
|
receipt.on('remove', ev.confirm);
|
||||||
|
|
||||||
|
// Calling this directly so we can wait for completion
|
||||||
|
return Whisper.ReadReceipts.onReceipt(receipt);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onVerified(ev) {
|
function onVerified(ev) {
|
||||||
|
@ -447,6 +450,9 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
receipt.on('remove', ev.confirm);
|
receipt.on('remove', ev.confirm);
|
||||||
|
|
||||||
|
// Calling this directly so we can wait for completion
|
||||||
|
return Whisper.DeliveryReceipts.onReceipt(receipt);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.owsDesktopApp = {
|
window.owsDesktopApp = {
|
||||||
|
|
|
@ -6,9 +6,6 @@
|
||||||
window.Whisper = window.Whisper || {};
|
window.Whisper = window.Whisper || {};
|
||||||
|
|
||||||
Whisper.DeliveryReceipts = new (Backbone.Collection.extend({
|
Whisper.DeliveryReceipts = new (Backbone.Collection.extend({
|
||||||
initialize: function() {
|
|
||||||
this.on('add', this.onReceipt);
|
|
||||||
},
|
|
||||||
forMessage: function(conversation, message) {
|
forMessage: function(conversation, message) {
|
||||||
var recipients;
|
var recipients;
|
||||||
if (conversation.isPrivate()) {
|
if (conversation.isPrivate()) {
|
||||||
|
@ -25,7 +22,7 @@
|
||||||
},
|
},
|
||||||
onReceipt: function(receipt) {
|
onReceipt: function(receipt) {
|
||||||
var messages = new Whisper.MessageCollection();
|
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; }
|
if (messages.length === 0) { return; }
|
||||||
var message = messages.find(function(message) {
|
var message = messages.find(function(message) {
|
||||||
return (!message.isIncoming() && receipt.get('source') === message.get('conversationId'));
|
return (!message.isIncoming() && receipt.get('source') === message.get('conversationId'));
|
||||||
|
@ -44,18 +41,21 @@
|
||||||
}).then(function(message) {
|
}).then(function(message) {
|
||||||
if (message) {
|
if (message) {
|
||||||
var deliveries = message.get('delivered') || 0;
|
var deliveries = message.get('delivered') || 0;
|
||||||
message.save({
|
return new Promise(function(resolve, reject) {
|
||||||
delivered: deliveries + 1
|
message.save({
|
||||||
}).then(function() {
|
delivered: deliveries + 1
|
||||||
// notify frontend listeners
|
}).then(function() {
|
||||||
var conversation = ConversationController.get(
|
// notify frontend listeners
|
||||||
message.get('conversationId')
|
var conversation = ConversationController.get(
|
||||||
);
|
message.get('conversationId')
|
||||||
if (conversation) {
|
);
|
||||||
conversation.trigger('delivered', message);
|
if (conversation) {
|
||||||
}
|
conversation.trigger('delivered', message);
|
||||||
|
}
|
||||||
|
|
||||||
this.remove(receipt);
|
this.remove(receipt);
|
||||||
|
resolve();
|
||||||
|
}.bind(this), reject);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
// TODO: consider keeping a list of numbers we've
|
// TODO: consider keeping a list of numbers we've
|
||||||
// successfully delivered to?
|
// successfully delivered to?
|
||||||
|
|
|
@ -5,9 +5,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
window.Whisper = window.Whisper || {};
|
window.Whisper = window.Whisper || {};
|
||||||
Whisper.ReadReceipts = new (Backbone.Collection.extend({
|
Whisper.ReadReceipts = new (Backbone.Collection.extend({
|
||||||
initialize: function() {
|
|
||||||
this.on('add', this.onReceipt);
|
|
||||||
},
|
|
||||||
forMessage: function(message) {
|
forMessage: function(message) {
|
||||||
var receipt = this.findWhere({
|
var receipt = this.findWhere({
|
||||||
sender: message.get('source'),
|
sender: message.get('source'),
|
||||||
|
@ -21,13 +18,13 @@
|
||||||
},
|
},
|
||||||
onReceipt: function(receipt) {
|
onReceipt: function(receipt) {
|
||||||
var messages = new Whisper.MessageCollection();
|
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) {
|
var message = messages.find(function(message) {
|
||||||
return (message.isIncoming() && message.isUnread() &&
|
return (message.isIncoming() && message.isUnread() &&
|
||||||
message.get('source') === receipt.get('sender'));
|
message.get('source') === receipt.get('sender'));
|
||||||
});
|
});
|
||||||
if (message) {
|
if (message) {
|
||||||
message.markRead(receipt.get('read_at')).then(function() {
|
return message.markRead(receipt.get('read_at')).then(function() {
|
||||||
this.notifyConversation(message);
|
this.notifyConversation(message);
|
||||||
this.remove(receipt);
|
this.remove(receipt);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue