2019-03-26 01:10:30 +00:00
|
|
|
/* global
|
|
|
|
Backbone,
|
|
|
|
Whisper,
|
|
|
|
MessageController
|
|
|
|
*/
|
2018-07-07 00:48:14 +00:00
|
|
|
|
|
|
|
/* eslint-disable more/no-then */
|
|
|
|
|
|
|
|
// eslint-disable-next-line func-names
|
2018-04-27 21:25:04 +00:00
|
|
|
(function() {
|
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
Whisper.ReadSyncs = new (Backbone.Collection.extend({
|
2018-07-07 00:48:14 +00:00
|
|
|
forMessage(message) {
|
2020-08-06 17:28:56 +00:00
|
|
|
const senderId = window.ConversationController.ensureContactIds({
|
|
|
|
e164: message.get('source'),
|
|
|
|
uuid: message.get('sourceUuid'),
|
|
|
|
});
|
2018-07-07 00:48:14 +00:00
|
|
|
const receipt = this.findWhere({
|
2020-08-06 17:28:56 +00:00
|
|
|
senderId,
|
2018-04-27 21:25:04 +00:00
|
|
|
timestamp: message.get('sent_at'),
|
|
|
|
});
|
|
|
|
if (receipt) {
|
2018-07-21 19:00:08 +00:00
|
|
|
window.log.info('Found early read sync for message');
|
2018-04-27 21:25:04 +00:00
|
|
|
this.remove(receipt);
|
|
|
|
return receipt;
|
|
|
|
}
|
2018-07-07 00:48:14 +00:00
|
|
|
|
|
|
|
return null;
|
2018-04-27 21:25:04 +00:00
|
|
|
},
|
2018-07-25 22:02:27 +00:00
|
|
|
async onReceipt(receipt) {
|
|
|
|
try {
|
|
|
|
const messages = await window.Signal.Data.getMessagesBySentAt(
|
|
|
|
receipt.get('timestamp'),
|
|
|
|
{
|
|
|
|
MessageCollection: Whisper.MessageCollection,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2020-08-06 17:28:56 +00:00
|
|
|
const found = messages.find(item => {
|
|
|
|
const senderId = window.ConversationController.ensureContactIds({
|
|
|
|
e164: item.get('source'),
|
|
|
|
uuid: item.get('sourceUuid'),
|
|
|
|
});
|
|
|
|
|
|
|
|
return item.isIncoming() && senderId === receipt.get('senderId');
|
|
|
|
});
|
2020-09-04 23:07:24 +00:00
|
|
|
if (found) {
|
|
|
|
Whisper.Notifications.removeBy({ messageId: found.id });
|
|
|
|
} else {
|
2019-09-26 19:56:31 +00:00
|
|
|
window.log.info(
|
|
|
|
'No message for read sync',
|
2020-08-06 17:28:56 +00:00
|
|
|
receipt.get('senderId'),
|
2019-09-26 19:56:31 +00:00
|
|
|
receipt.get('sender'),
|
2020-03-05 21:14:58 +00:00
|
|
|
receipt.get('senderUuid'),
|
2019-09-26 19:56:31 +00:00
|
|
|
receipt.get('timestamp')
|
|
|
|
);
|
2018-07-25 22:02:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-26 01:10:30 +00:00
|
|
|
const message = MessageController.register(found.id, found);
|
2018-08-06 18:31:41 +00:00
|
|
|
const readAt = receipt.get('read_at');
|
|
|
|
|
|
|
|
// If message is unread, we mark it read. Otherwise, we update the expiration
|
|
|
|
// timer to the time specified by the read sync if it's earlier than
|
|
|
|
// the previous read time.
|
|
|
|
if (message.isUnread()) {
|
2019-09-26 19:56:31 +00:00
|
|
|
await message.markRead(readAt, { skipSave: true });
|
2018-08-06 18:31:41 +00:00
|
|
|
|
|
|
|
// onReadMessage may result in messages older than this one being
|
|
|
|
// marked read. We want those messages to have the same expire timer
|
|
|
|
// start time as this one, so we pass the readAt value through.
|
|
|
|
const conversation = message.getConversation();
|
|
|
|
if (conversation) {
|
|
|
|
conversation.onReadMessage(message, readAt);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const now = Date.now();
|
|
|
|
const existingTimestamp = message.get('expirationStartTimestamp');
|
|
|
|
const expirationStartTimestamp = Math.min(
|
|
|
|
now,
|
|
|
|
Math.min(existingTimestamp || now, readAt || now)
|
|
|
|
);
|
|
|
|
message.set({ expirationStartTimestamp });
|
|
|
|
|
|
|
|
const force = true;
|
2019-09-26 19:56:31 +00:00
|
|
|
await message.setToExpire(force, { skipSave: true });
|
2018-08-06 18:31:41 +00:00
|
|
|
|
|
|
|
const conversation = message.getConversation();
|
|
|
|
if (conversation) {
|
|
|
|
conversation.trigger('expiration-change', message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-26 19:56:31 +00:00
|
|
|
await window.Signal.Data.saveMessage(message.attributes, {
|
|
|
|
Message: Whisper.Message,
|
|
|
|
});
|
|
|
|
|
2018-07-25 22:02:27 +00:00
|
|
|
this.remove(receipt);
|
|
|
|
} catch (error) {
|
|
|
|
window.log.error(
|
|
|
|
'ReadSyncs.onReceipt error:',
|
|
|
|
error && error.stack ? error.stack : error
|
|
|
|
);
|
|
|
|
}
|
2018-04-27 21:25:04 +00:00
|
|
|
},
|
|
|
|
}))();
|
Feature: Blue check marks for read messages if opted in (#1489)
* Refactor delivery receipt event handler
* Rename the delivery receipt event
For less ambiguity with read receipts.
* Rename synced read event
For less ambiguity with read receipts from other Signal users.
* Add support for incoming receipt messages
Handle ReceiptMessages, which may include encrypted delivery receipts or read
receipts from recipients of our sent messages.
// FREEBIE
* Rename ReadReceipts to ReadSyncs
* Render read messages with blue double checks
* Send read receipts to senders of incoming messages
// FREEBIE
* Move ReadSyncs to their own file
// FREEBIE
* Fixup old comments on read receipts (now read syncs)
And some variable renaming for extra clarity.
// FREEBIE
* Add global setting for read receipts
Don't send read receipt messages unless the setting is enabled.
Don't process read receipts if the setting is disabled.
// FREEBIE
* Sync read receipt setting from mobile
Toggling this setting on your mobile device should sync it to Desktop. When
linking, use the setting in the provisioning message.
// FREEBIE
* Send receipt messages silently
Avoid generating phantom messages on ios
// FREEBIE
* Save recipients on the outgoing message models
For accurate tracking and display of sent/delivered/read state, even if group
membership changes later.
// FREEBIE
* Fix conversation type in profile key update handling
// FREEBIE
* Set recipients on synced sent messages
* Render saved recipients in message detail if available
For older messages, where we did not save the intended set of recipients at the
time of sending, fall back to the current group membership.
// FREEBIE
* Record who has been successfully sent to
// FREEBIE
* Record who a message has been delivered to
* Invert the not-clickable class
* Fix readReceipt setting sync when linking
* Render per recipient sent/delivered/read status
In the message detail view for outgoing messages, render each recipient's
individual sent/delivered/read status with respect to this message, as long as
there are no errors associated with the recipient (ie, safety number changes,
user not registered, etc...) since the error icon is displayed in that case.
*Messages sent before this change may not have per-recipient status lists
and will simply show no status icon.
// FREEBIE
* Add configuration sync request
Send these requests in a one-off fashion when:
1. We have just setup from a chrome app import
2. We have just upgraded to read-receipt support
// FREEBIE
* Expose sendRequestConfigurationSyncMessage
// FREEBIE
* Fix handling of incoming delivery receipts - union with array
FREEBIE
2017-10-04 22:28:43 +00:00
|
|
|
})();
|