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:
@@ -247,10 +247,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onReadReceipt(ev) {
|
function onReadReceipt(ev) {
|
||||||
var timestamp = ev.timestamp.toNumber();
|
var read_at = ev.timestamp;
|
||||||
var sender = ev.sender;
|
var timestamp = ev.read.timestamp;
|
||||||
|
var sender = ev.read.sender;
|
||||||
console.log('read receipt ', sender, timestamp);
|
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
|
// lazy hack
|
||||||
|
@@ -38325,16 +38325,19 @@ MessageReceiver.prototype.extend({
|
|||||||
} else if (syncMessage.read) {
|
} else if (syncMessage.read) {
|
||||||
console.log('read messages',
|
console.log('read messages',
|
||||||
'from', envelope.source + '.' + envelope.sourceDevice);
|
'from', envelope.source + '.' + envelope.sourceDevice);
|
||||||
this.handleRead(syncMessage.read);
|
this.handleRead(syncMessage.read, envelope.timestamp);
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Got empty SyncMessage');
|
throw new Error('Got empty SyncMessage');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleRead: function(read) {
|
handleRead: function(read, timestamp) {
|
||||||
for (var i = 0; i < read.length; ++i) {
|
for (var i = 0; i < read.length; ++i) {
|
||||||
var ev = new Event('read');
|
var ev = new Event('read');
|
||||||
ev.timestamp = read[i].timestamp;
|
ev.timestamp = timestamp.toNumber();
|
||||||
ev.sender = read[i].sender;
|
ev.read = {
|
||||||
|
timestamp : read[i].timestamp.toNumber(),
|
||||||
|
sender : read[i].sender
|
||||||
|
}
|
||||||
this.dispatchEvent(ev);
|
this.dispatchEvent(ev);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@@ -374,10 +374,10 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
markRead: function() {
|
markRead: function(read_at) {
|
||||||
this.unset('unread');
|
this.unset('unread');
|
||||||
if (this.get('expireTimer') && !this.get('expirationStartTimestamp')) {
|
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({
|
Whisper.Notifications.remove(Whisper.Notifications.where({
|
||||||
messageId: this.id
|
messageId: this.id
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
});
|
});
|
||||||
if (message) {
|
if (message) {
|
||||||
this.remove(receipt);
|
this.remove(receipt);
|
||||||
message.markRead().then(function() {
|
message.markRead(receipt.get('read_at')).then(function() {
|
||||||
var conversation = ConversationController.get({
|
var conversation = ConversationController.get({
|
||||||
id: message.get('conversationId')
|
id: message.get('conversationId')
|
||||||
});
|
});
|
||||||
|
@@ -254,16 +254,19 @@ MessageReceiver.prototype.extend({
|
|||||||
} else if (syncMessage.read) {
|
} else if (syncMessage.read) {
|
||||||
console.log('read messages',
|
console.log('read messages',
|
||||||
'from', envelope.source + '.' + envelope.sourceDevice);
|
'from', envelope.source + '.' + envelope.sourceDevice);
|
||||||
this.handleRead(syncMessage.read);
|
this.handleRead(syncMessage.read, envelope.timestamp);
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Got empty SyncMessage');
|
throw new Error('Got empty SyncMessage');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleRead: function(read) {
|
handleRead: function(read, timestamp) {
|
||||||
for (var i = 0; i < read.length; ++i) {
|
for (var i = 0; i < read.length; ++i) {
|
||||||
var ev = new Event('read');
|
var ev = new Event('read');
|
||||||
ev.timestamp = read[i].timestamp;
|
ev.timestamp = timestamp.toNumber();
|
||||||
ev.sender = read[i].sender;
|
ev.read = {
|
||||||
|
timestamp : read[i].timestamp.toNumber(),
|
||||||
|
sender : read[i].sender
|
||||||
|
}
|
||||||
this.dispatchEvent(ev);
|
this.dispatchEvent(ev);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user