Process group updates before sync delivery receipts
Because we need to know the group members to find early-arrival receipts.
This commit is contained in:
parent
654373d743
commit
1ed0ef5bc3
1 changed files with 32 additions and 32 deletions
|
@ -139,38 +139,6 @@
|
||||||
}
|
}
|
||||||
var conversation = new Whisper.Conversation({id: conversationId});
|
var conversation = new Whisper.Conversation({id: conversationId});
|
||||||
conversation.fetch().always(function() {
|
conversation.fetch().always(function() {
|
||||||
var type = 'incoming';
|
|
||||||
if (pushMessageContent.sync) {
|
|
||||||
type = 'outgoing';
|
|
||||||
timestamp = pushMessageContent.sync.timestamp.toNumber();
|
|
||||||
|
|
||||||
// lazy hack - check for receipts that arrived early.
|
|
||||||
if (pushMessageContent.sync.destination) {
|
|
||||||
var receipt = window.receipts.findWhere({
|
|
||||||
timestamp: timestamp,
|
|
||||||
source: pushMessageContent.sync.destination
|
|
||||||
});
|
|
||||||
if (receipt) {
|
|
||||||
window.receipts.remove(receipt);
|
|
||||||
message.set({
|
|
||||||
delivered: (message.get('delivered') || 0) + 1
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else if (pushMessageContent.group.id) { // group sync
|
|
||||||
var members = conversation.get('members');
|
|
||||||
var receipts = window.receipts.where({ timestamp: timestamp });
|
|
||||||
for (var i in receipts) {
|
|
||||||
if (members.indexOf(receipts[i].get('source')) > -1) {
|
|
||||||
window.receipts.remove(receipts[i]);
|
|
||||||
message.set({
|
|
||||||
delivered: (message.get('delivered') || 0) + 1
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new Error('Received sync message with no destination and no group id');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var now = new Date().getTime();
|
var now = new Date().getTime();
|
||||||
var attributes = {};
|
var attributes = {};
|
||||||
if (pushMessageContent.group) {
|
if (pushMessageContent.group) {
|
||||||
|
@ -202,6 +170,38 @@
|
||||||
message.set({group_update: group_update});
|
message.set({group_update: group_update});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var type = 'incoming';
|
||||||
|
if (pushMessageContent.sync) {
|
||||||
|
type = 'outgoing';
|
||||||
|
timestamp = pushMessageContent.sync.timestamp.toNumber();
|
||||||
|
|
||||||
|
// lazy hack - check for receipts that arrived early.
|
||||||
|
if (pushMessageContent.sync.destination) {
|
||||||
|
var receipt = window.receipts.findWhere({
|
||||||
|
timestamp: timestamp,
|
||||||
|
source: pushMessageContent.sync.destination
|
||||||
|
});
|
||||||
|
if (receipt) {
|
||||||
|
window.receipts.remove(receipt);
|
||||||
|
message.set({
|
||||||
|
delivered: (message.get('delivered') || 0) + 1
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if (pushMessageContent.group.id) { // group sync
|
||||||
|
var members = conversation.get('members') || [];
|
||||||
|
var receipts = window.receipts.where({ timestamp: timestamp });
|
||||||
|
for (var i in receipts) {
|
||||||
|
if (members.indexOf(receipts[i].get('source')) > -1) {
|
||||||
|
window.receipts.remove(receipts[i]);
|
||||||
|
message.set({
|
||||||
|
delivered: (message.get('delivered') || 0) + 1
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error('Received sync message with no destination and no group id');
|
||||||
|
}
|
||||||
|
}
|
||||||
attributes.active_at = now;
|
attributes.active_at = now;
|
||||||
if (type === 'incoming') {
|
if (type === 'incoming') {
|
||||||
attributes.unreadCount = conversation.get('unreadCount') + 1;
|
attributes.unreadCount = conversation.get('unreadCount') + 1;
|
||||||
|
|
Loading…
Reference in a new issue