Introduce new urgent property for outgoing messages

This commit is contained in:
Scott Nonnenberg 2022-07-01 09:55:13 -07:00 committed by GitHub
parent 6cd1e3fdfc
commit 06190b1434
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 302 additions and 83 deletions

View file

@ -2,7 +2,7 @@
// SPDX-License-Identifier: AGPL-3.0-only
import { z } from 'zod';
import { isNumber } from 'lodash';
import { isBoolean, isNumber } from 'lodash';
import type { CallbackResultType } from '../textsecure/Types.d';
import dataInterface from '../sql/Client';
import * as log from '../logging/log';
@ -17,38 +17,49 @@ import { SEALED_SENDER } from '../types/SealedSender';
const { insertSentProto, updateConversation } = dataInterface;
export const sendTypesEnum = z.enum([
'blockSyncRequest',
'pniIdentitySyncRequest',
'callingMessage', // excluded from send log
'configurationSyncRequest',
'contactSyncRequest',
'deleteForEveryone',
'deliveryReceipt',
'expirationTimerUpdate',
'fetchLatestManifestSync',
'fetchLocalProfileSync',
'groupChange',
'groupSyncRequest',
'keySyncRequest',
'legacyGroupChange',
// Core user interactions, default urgent
'message',
'messageRequestSync',
'callingMessage', // excluded from send log; only call-initiation messages are urgent
'deleteForEveryone',
'expirationTimerUpdate', // non-urgent
'groupChange', // non-urgent
'reaction',
'typing', // excluded from send log; non-urgent
// Responding to incoming messages, all non-urgent
'deliveryReceipt',
'readReceipt',
'viewedReceipt',
// Encryption housekeeping, default non-urgent
'nullMessage',
'profileKeyUpdate',
'reaction',
'readReceipt',
'readSync',
'resendFromLog', // excluded from send log
'resetSession',
'resendFromLog', // excluded from send log, only urgent if original message was urgent
'retryRequest', // excluded from send log
'senderKeyDistributionMessage',
'senderKeyDistributionMessage', // only urgent if associated message is
// Sync messages sent during link, default non-urgent
'blockSyncRequest',
'configurationSyncRequest',
'contactSyncRequest', // urgent because it blocks the link process
'groupSyncRequest',
'keySyncRequest', // urgent because it blocks the link process
'pniIdentitySyncRequest', // urgent because we need our PNI to be fully functional
// Syncs, default non-urgent
'fetchLatestManifestSync',
'fetchLocalProfileSync',
'messageRequestSync',
'readSync', // urgent
'sentSync',
'stickerPackSync',
'typing', // excluded from send log
'verificationSync',
'viewOnceSync',
'viewSync',
'viewedReceipt',
// No longer used, all non-urgent
'legacyGroupChange',
'resetSession',
]);
export type SendTypesType = z.infer<typeof sendTypesEnum>;
@ -216,7 +227,7 @@ async function maybeSaveToSendLog(
sendType: SendTypesType;
}
): Promise<void> {
const { contentHint, contentProto, recipients, timestamp } = result;
const { contentHint, contentProto, recipients, timestamp, urgent } = result;
if (!shouldSaveProto(sendType)) {
return;
@ -247,6 +258,7 @@ async function maybeSaveToSendLog(
timestamp,
proto: Buffer.from(contentProto),
contentHint,
urgent: isBoolean(urgent) ? urgent : true,
},
{
messageIds,

View file

@ -5,7 +5,7 @@ import {
DecryptionErrorMessage,
PlaintextContent,
} from '@signalapp/libsignal-client';
import { isNumber } from 'lodash';
import { isBoolean, isNumber } from 'lodash';
import * as Bytes from '../Bytes';
import { isProduction } from './version';
@ -131,7 +131,7 @@ export async function onRetryRequest(event: RetryRequestEvent): Promise<void> {
throw new Error(`onRetryRequest/${logId}: messaging is not available!`);
}
const { contentHint, messageIds, proto, timestamp } = sentProto;
const { contentHint, messageIds, proto, timestamp, urgent } = sentProto;
const { contentProto, groupId } = await maybeAddSenderKeyDistributionMessage({
contentProto: Proto.Content.decode(proto),
@ -148,12 +148,13 @@ export async function onRetryRequest(event: RetryRequestEvent): Promise<void> {
);
const sendOptions = await getSendOptions(recipientConversation.attributes);
const promise = messaging.sendMessageProtoAndWait({
timestamp,
recipients: [requesterUuid],
proto: new Proto.Content(contentProto),
contentHint,
groupId,
options: sendOptions,
proto: new Proto.Content(contentProto),
recipients: [requesterUuid],
timestamp,
urgent,
});
await handleMessageSend(promise, {
@ -306,6 +307,7 @@ async function sendDistributionMessageOrNullMessage(
groupId,
identifiers: [requesterUuid],
throwIfNotInDatabase: true,
urgent: false,
},
sendOptions
),
@ -346,6 +348,7 @@ async function sendDistributionMessageOrNullMessage(
Bytes.fromBase64(nullMessage.protoBase64)
),
timestamp: Date.now(),
urgent: isBoolean(nullMessage.urgent) ? nullMessage.urgent : true,
}),
{ messageIds: [], sendType: nullMessage.type }
);

View file

@ -98,6 +98,7 @@ export async function sendToGroup({
sendOptions,
sendTarget,
sendType,
urgent,
}: {
abortSignal?: AbortSignal;
contentHint: number;
@ -107,6 +108,7 @@ export async function sendToGroup({
sendOptions?: SendOptionsType;
sendTarget: SenderKeyTargetType;
sendType: SendTypesType;
urgent: boolean;
}): Promise<CallbackResultType> {
strictAssert(
window.textsecure.messaging,
@ -139,6 +141,7 @@ export async function sendToGroup({
sendTarget,
sendType,
timestamp,
urgent,
});
}
@ -153,6 +156,7 @@ export async function sendContentMessageToGroup({
sendTarget,
sendType,
timestamp,
urgent,
}: {
contentHint: number;
contentMessage: Proto.Content;
@ -164,6 +168,7 @@ export async function sendContentMessageToGroup({
sendTarget: SenderKeyTargetType;
sendType: SendTypesType;
timestamp: number;
urgent: boolean;
}): Promise<CallbackResultType> {
const logId = sendTarget.idForLogging();
strictAssert(
@ -194,6 +199,7 @@ export async function sendContentMessageToGroup({
sendTarget,
sendType,
timestamp,
urgent,
});
} catch (error: unknown) {
if (!(error instanceof Error)) {
@ -217,6 +223,7 @@ export async function sendContentMessageToGroup({
proto: Buffer.from(Proto.Content.encode(contentMessage).finish()),
sendType,
timestamp,
urgent,
});
const groupId = sendTarget.isGroupV2() ? sendTarget.getGroupId() : undefined;
return window.textsecure.messaging.sendGroupProto({
@ -227,6 +234,7 @@ export async function sendContentMessageToGroup({
recipients,
sendLogCallback,
timestamp,
urgent,
});
}
@ -244,6 +252,7 @@ export async function sendToGroupViaSenderKey(options: {
sendTarget: SenderKeyTargetType;
sendType: SendTypesType;
timestamp: number;
urgent: boolean;
}): Promise<CallbackResultType> {
const {
contentHint,
@ -257,6 +266,7 @@ export async function sendToGroupViaSenderKey(options: {
sendTarget,
sendType,
timestamp,
urgent,
} = options;
const { ContentHint } = Proto.UnidentifiedSenderMessage.Message;
@ -421,6 +431,7 @@ export async function sendToGroupViaSenderKey(options: {
distributionId,
groupId,
identifiers: newToMemberUuids,
urgent,
},
sendOptions ? { ...sendOptions, online: false } : undefined
),
@ -495,11 +506,11 @@ export async function sendToGroupViaSenderKey(options: {
});
const accessKeys = getXorOfAccessKeys(devicesForSenderKey);
const result = await window.textsecure.messaging.sendWithSenderKey(
const result = await window.textsecure.messaging.server.sendWithSenderKey(
messageBuffer,
accessKeys,
timestamp,
online
{ online, urgent }
);
const parsed = multiRecipient200ResponseSchema.safeParse(result);
@ -531,6 +542,7 @@ export async function sendToGroupViaSenderKey(options: {
contentHint,
proto: Buffer.from(Proto.Content.encode(contentMessage).finish()),
timestamp,
urgent,
},
{
recipients: senderKeyRecipientsWithDevices,
@ -598,6 +610,7 @@ export async function sendToGroupViaSenderKey(options: {
timestamp,
contentProto: Buffer.from(Proto.Content.encode(contentMessage).finish()),
recipients: senderKeyRecipientsWithDevices,
urgent,
};
}
@ -648,6 +661,7 @@ export async function sendToGroupViaSenderKey(options: {
recipients: normalSendRecipients,
sendLogCallback,
timestamp,
urgent,
});
return mergeSendResult({

View file

@ -89,6 +89,7 @@ export async function wrapWithSyncMessageSend({
expirationStartTimestamp: null,
options,
timestamp,
urgent: false,
}),
{ messageIds, sendType: sendType === 'message' ? 'sentSync' : sendType }
);