OutgoingMessage: Use enqueueSessionJob for all encrypts

This commit is contained in:
Scott Nonnenberg 2021-05-04 18:03:03 -07:00 committed by GitHub
parent 7c2f233384
commit 18c86898d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -45,6 +45,13 @@ export const enum SenderCertificateMode {
WithoutE164, WithoutE164,
} }
type SendMetadata = {
type: number;
destinationDeviceId: number;
destinationRegistrationId: number;
content: string;
};
export const serializedCertificateSchema = z export const serializedCertificateSchema = z
.object({ .object({
expires: z.number().optional(), expires: z.number().optional(),
@ -434,14 +441,23 @@ export default class OutgoingMessage {
return Promise.all( return Promise.all(
deviceIds.map(async destinationDeviceId => { deviceIds.map(async destinationDeviceId => {
const address = `${identifier}.${destinationDeviceId}`;
return window.textsecure.storage.protocol.enqueueSessionJob<SendMetadata>(
address,
async () => {
const protocolAddress = ProtocolAddress.new( const protocolAddress = ProtocolAddress.new(
identifier, identifier,
destinationDeviceId destinationDeviceId
); );
const activeSession = await sessionStore.getSession(protocolAddress); const activeSession = await sessionStore.getSession(
protocolAddress
);
if (!activeSession) { if (!activeSession) {
throw new Error('OutgoingMessage.doSendMessage: No active sesssion!'); throw new Error(
'OutgoingMessage.doSendMessage: No active sesssion!'
);
} }
const destinationRegistrationId = activeSession.remoteRegistrationId(); const destinationRegistrationId = activeSession.remoteRegistrationId();
@ -460,7 +476,8 @@ export default class OutgoingMessage {
); );
return { return {
type: window.textsecure.protobuf.Envelope.Type.UNIDENTIFIED_SENDER, type:
window.textsecure.protobuf.Envelope.Type.UNIDENTIFIED_SENDER,
destinationDeviceId, destinationDeviceId,
destinationRegistrationId, destinationRegistrationId,
content: buffer.toString('base64'), content: buffer.toString('base64'),
@ -483,9 +500,11 @@ export default class OutgoingMessage {
destinationRegistrationId, destinationRegistrationId,
content: ciphertextMessage.serialize().toString('base64'), content: ciphertextMessage.serialize().toString('base64'),
}; };
}
);
}) })
) )
.then(async jsonData => { .then(async (jsonData: Array<SendMetadata>) => {
if (sealedSender) { if (sealedSender) {
return this.transmitMessage(identifier, jsonData, this.timestamp, { return this.transmitMessage(identifier, jsonData, this.timestamp, {
accessKey, accessKey,