Remove the word "receipt" from read syncs code

This commit is contained in:
Evan Hahn 2021-08-02 11:47:59 -05:00 committed by GitHub
parent 926283a114
commit 73bcd3b531
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 23 deletions

View file

@ -3820,7 +3820,7 @@ export async function startApp(): Promise<void> {
// Note: Here we wait, because we want read states to be in the database // Note: Here we wait, because we want read states to be in the database
// before we move on. // before we move on.
return ReadSyncs.getSingleton().onReceipt(receipt); return ReadSyncs.getSingleton().onSync(receipt);
}); });
} }

View file

@ -21,21 +21,19 @@ class ReadSyncModel extends Model<ReadSyncAttributesType> {}
let singleton: ReadSyncs | undefined; let singleton: ReadSyncs | undefined;
async function maybeItIsAReactionReadSync( async function maybeItIsAReactionReadSync(sync: ReadSyncModel): Promise<void> {
receipt: ReadSyncModel
): Promise<void> {
const readReaction = await window.Signal.Data.markReactionAsRead( const readReaction = await window.Signal.Data.markReactionAsRead(
receipt.get('senderUuid'), sync.get('senderUuid'),
Number(receipt.get('timestamp')) Number(sync.get('timestamp'))
); );
if (!readReaction) { if (!readReaction) {
window.log.info( window.log.info(
'Nothing found for read sync', 'Nothing found for read sync',
receipt.get('senderId'), sync.get('senderId'),
receipt.get('sender'), sync.get('sender'),
receipt.get('senderUuid'), sync.get('senderUuid'),
receipt.get('timestamp') sync.get('timestamp')
); );
return; return;
} }
@ -62,25 +60,25 @@ export class ReadSyncs extends Collection {
e164: message.get('source'), e164: message.get('source'),
uuid: message.get('sourceUuid'), uuid: message.get('sourceUuid'),
}); });
const receipt = this.find(item => { const sync = this.find(item => {
return ( return (
item.get('senderId') === senderId && item.get('senderId') === senderId &&
item.get('timestamp') === message.get('sent_at') item.get('timestamp') === message.get('sent_at')
); );
}); });
if (receipt) { if (sync) {
window.log.info('Found early read sync for message'); window.log.info('Found early read sync for message');
this.remove(receipt); this.remove(sync);
return receipt; return sync;
} }
return null; return null;
} }
async onReceipt(receipt: ReadSyncModel): Promise<void> { async onSync(sync: ReadSyncModel): Promise<void> {
try { try {
const messages = await window.Signal.Data.getMessagesBySentAt( const messages = await window.Signal.Data.getMessagesBySentAt(
receipt.get('timestamp'), sync.get('timestamp'),
{ {
MessageCollection: window.Whisper.MessageCollection, MessageCollection: window.Whisper.MessageCollection,
} }
@ -92,20 +90,18 @@ export class ReadSyncs extends Collection {
uuid: item.get('sourceUuid'), uuid: item.get('sourceUuid'),
}); });
return ( return isIncoming(item.attributes) && senderId === sync.get('senderId');
isIncoming(item.attributes) && senderId === receipt.get('senderId')
);
}); });
if (!found) { if (!found) {
await maybeItIsAReactionReadSync(receipt); await maybeItIsAReactionReadSync(sync);
return; return;
} }
window.Whisper.Notifications.removeBy({ messageId: found.id }); window.Whisper.Notifications.removeBy({ messageId: found.id });
const message = window.MessageController.register(found.id, found); const message = window.MessageController.register(found.id, found);
const readAt = receipt.get('readAt'); const readAt = sync.get('readAt');
// If message is unread, we mark it read. Otherwise, we update the expiration // 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 // timer to the time specified by the read sync if it's earlier than
@ -147,10 +143,10 @@ export class ReadSyncs extends Collection {
window.Signal.Util.queueUpdateMessage(message.attributes); window.Signal.Util.queueUpdateMessage(message.attributes);
this.remove(receipt); this.remove(sync);
} catch (error) { } catch (error) {
window.log.error( window.log.error(
'ReadSyncs.onReceipt error:', 'ReadSyncs.onSync error:',
error && error.stack ? error.stack : error error && error.stack ? error.stack : error
); );
} }