Use read receipt envelope to infer startExpirationTime

Avoids display of phantom messages that are only received and marked
read locally long after they have expired on another linked device.
This commit is contained in:
lilia 2016-09-21 15:06:31 -07:00
parent 96fd017890
commit 02ea4f2475
5 changed files with 25 additions and 14 deletions

View file

@ -247,10 +247,15 @@
}
function onReadReceipt(ev) {
var timestamp = ev.timestamp.toNumber();
var sender = ev.sender;
var read_at = ev.timestamp;
var timestamp = ev.read.timestamp;
var sender = ev.read.sender;
console.log('read receipt ', sender, timestamp);
Whisper.ReadReceipts.add({sender: sender, timestamp: timestamp});
Whisper.ReadReceipts.add({
sender : sender,
timestamp : timestamp,
read_at : read_at
});
}
// lazy hack

View file

@ -38325,16 +38325,19 @@ MessageReceiver.prototype.extend({
} else if (syncMessage.read) {
console.log('read messages',
'from', envelope.source + '.' + envelope.sourceDevice);
this.handleRead(syncMessage.read);
this.handleRead(syncMessage.read, envelope.timestamp);
} else {
throw new Error('Got empty SyncMessage');
}
},
handleRead: function(read) {
handleRead: function(read, timestamp) {
for (var i = 0; i < read.length; ++i) {
var ev = new Event('read');
ev.timestamp = read[i].timestamp;
ev.sender = read[i].sender;
ev.timestamp = timestamp.toNumber();
ev.read = {
timestamp : read[i].timestamp.toNumber(),
sender : read[i].sender
}
this.dispatchEvent(ev);
}
},

View file

@ -374,10 +374,10 @@
});
});
},
markRead: function() {
markRead: function(read_at) {
this.unset('unread');
if (this.get('expireTimer') && !this.get('expirationStartTimestamp')) {
this.set('expirationStartTimestamp', Date.now());
this.set('expirationStartTimestamp', read_at || Date.now());
}
Whisper.Notifications.remove(Whisper.Notifications.where({
messageId: this.id

View file

@ -28,7 +28,7 @@
});
if (message) {
this.remove(receipt);
message.markRead().then(function() {
message.markRead(receipt.get('read_at')).then(function() {
var conversation = ConversationController.get({
id: message.get('conversationId')
});

View file

@ -254,16 +254,19 @@ MessageReceiver.prototype.extend({
} else if (syncMessage.read) {
console.log('read messages',
'from', envelope.source + '.' + envelope.sourceDevice);
this.handleRead(syncMessage.read);
this.handleRead(syncMessage.read, envelope.timestamp);
} else {
throw new Error('Got empty SyncMessage');
}
},
handleRead: function(read) {
handleRead: function(read, timestamp) {
for (var i = 0; i < read.length; ++i) {
var ev = new Event('read');
ev.timestamp = read[i].timestamp;
ev.sender = read[i].sender;
ev.timestamp = timestamp.toNumber();
ev.read = {
timestamp : read[i].timestamp.toNumber(),
sender : read[i].sender
}
this.dispatchEvent(ev);
}
},