Don't enqueue viewed receipt jobs for outgoing messages

This commit is contained in:
Evan Hahn 2021-11-03 12:02:26 -05:00 committed by GitHub
parent 7f9beef055
commit 562d15dd14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 20 deletions

View file

@ -51,7 +51,7 @@ export class ViewedReceiptsJobQueue extends JobQueue<ViewedReceiptsJobData> {
} }
try { try {
await sendViewedReceipt(data.viewedReceipt); await sendViewedReceipt(data.viewedReceipt, log);
} catch (err: unknown) { } catch (err: unknown) {
await handleCommonJobRequestError({ err, log, timeRemaining }); await handleCommonJobRequestError({ err, log, timeRemaining });
} }

View file

@ -2,25 +2,43 @@
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
import type { ConversationAttributesType } from '../model-types.d'; import type { ConversationAttributesType } from '../model-types.d';
import type { LoggerType } from '../types/Logging';
import { getSendOptions } from './getSendOptions'; import { getSendOptions } from './getSendOptions';
import { handleMessageSend } from './handleMessageSend'; import { handleMessageSend } from './handleMessageSend';
import { isConversationAccepted } from './isConversationAccepted'; import { isConversationAccepted } from './isConversationAccepted';
export async function sendViewedReceipt({ export async function sendViewedReceipt(
messageId, {
senderE164, messageId,
senderUuid, senderE164,
timestamp, senderUuid,
}: Readonly<{ timestamp,
messageId: string; }: Readonly<{
senderE164?: string; messageId: string;
senderUuid?: string; senderE164?: string;
timestamp: number; senderUuid?: string;
}>): Promise<void> { timestamp: number;
}>,
log: LoggerType
): Promise<void> {
if (!window.storage.get('read-receipt-setting')) { if (!window.storage.get('read-receipt-setting')) {
return; return;
} }
// We introduced a bug in `75f0cd50beff73885ebae92e4ac977de9f56d6c9` where we'd enqueue
// jobs that had no sender information. These jobs cannot possibly succeed. This
// removes them from the queue to avoid constantly retrying something.
//
// We should be able to safely remove this check after the fix has been present for
// awhile. Probably ~40 days from when this is first deployed (30 days to unlink + 10
// days of buffer).
if (!senderE164 && !senderUuid) {
log.error(
'sendViewedReceipt: no sender E164 or UUID. Cannot possibly complete this job. Giving up'
);
return;
}
const conversationId = window.ConversationController.ensureContactIds({ const conversationId = window.ConversationController.ensureContactIds({
e164: senderE164, e164: senderE164,
uuid: senderUuid, uuid: senderUuid,

View file

@ -45,6 +45,7 @@ import * as Bytes from '../Bytes';
import { import {
canReply, canReply,
getAttachmentsForMessage, getAttachmentsForMessage,
isIncoming,
isOutgoing, isOutgoing,
isTapToView, isTapToView,
} from '../state/selectors/message'; } from '../state/selectors/message';
@ -919,14 +920,16 @@ export class ConversationView extends window.Backbone.View<ConversationModel> {
message.set(markViewed(message.attributes, Date.now())); message.set(markViewed(message.attributes, Date.now()));
viewedReceiptsJobQueue.add({ if (isIncoming(message.attributes)) {
viewedReceipt: { viewedReceiptsJobQueue.add({
messageId, viewedReceipt: {
senderE164, messageId,
senderUuid, senderE164,
timestamp, senderUuid,
}, timestamp,
}); },
});
}
viewSyncJobQueue.add({ viewSyncJobQueue.add({
viewSyncs: [ viewSyncs: [