More protobufjs migration

This commit is contained in:
Fedor Indutny 2021-07-09 12:36:10 -07:00 committed by GitHub
parent cf06e6638e
commit ddbbe3a6b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
70 changed files with 3967 additions and 3369 deletions

View file

@ -37,7 +37,7 @@ import {
multiRecipient409ResponseSchema,
multiRecipient410ResponseSchema,
} from '../textsecure/WebAPI';
import { ContentClass } from '../textsecure.d';
import { SignalService as Proto } from '../protobuf';
import { assert } from './assert';
import { isGroupV2 } from './whatTypeOfConversation';
@ -53,6 +53,9 @@ const MAX_CONCURRENCY = 5;
// sendWithSenderKey is recursive, but we don't want to loop back too many times.
const MAX_RECURSION = 5;
// TODO: remove once we move away from ArrayBuffers
const FIXMEU8 = Uint8Array;
// Public API:
export async function sendToGroup({
@ -106,7 +109,7 @@ export async function sendContentMessageToGroup({
timestamp,
}: {
contentHint: number;
contentMessage: ContentClass;
contentMessage: Proto.Content;
conversation: ConversationModel;
isPartialSend?: boolean;
online?: boolean;
@ -165,7 +168,7 @@ export async function sendContentMessageToGroup({
export async function sendToGroupViaSenderKey(options: {
contentHint: number;
contentMessage: ContentClass;
contentMessage: Proto.Content;
conversation: ConversationModel;
isPartialSend?: boolean;
online?: boolean;
@ -185,9 +188,7 @@ export async function sendToGroupViaSenderKey(options: {
sendOptions,
timestamp,
} = options;
const {
ContentHint,
} = window.textsecure.protobuf.UnidentifiedSenderMessage.Message;
const { ContentHint } = Proto.UnidentifiedSenderMessage.Message;
const logId = conversation.idForLogging();
window.log.info(
@ -372,7 +373,9 @@ export async function sendToGroupViaSenderKey(options: {
contentHint,
devices: devicesForSenderKey,
distributionId,
contentMessage: contentMessage.toArrayBuffer(),
contentMessage: toArrayBuffer(
Proto.Content.encode(contentMessage).finish()
),
groupId,
});
const accessKeys = getXorOfAccessKeys(devicesForSenderKey);
@ -431,7 +434,11 @@ export async function sendToGroupViaSenderKey(options: {
const normalRecipients = getUuidsFromDevices(devicesForNormalSend);
if (normalRecipients.length === 0) {
return {
dataMessage: contentMessage.dataMessage?.toArrayBuffer(),
dataMessage: contentMessage.dataMessage
? toArrayBuffer(
Proto.DataMessage.encode(contentMessage.dataMessage).finish()
)
: undefined,
successfulIdentifiers: senderKeyRecipients,
unidentifiedDeliveries: senderKeyRecipients,
};
@ -449,7 +456,11 @@ export async function sendToGroupViaSenderKey(options: {
});
return {
dataMessage: contentMessage.dataMessage?.toArrayBuffer(),
dataMessage: contentMessage.dataMessage
? toArrayBuffer(
Proto.DataMessage.encode(contentMessage.dataMessage).finish()
)
: undefined,
errors: normalSendResult.errors,
failoverIdentifiers: normalSendResult.failoverIdentifiers,
successfulIdentifiers: [
@ -669,7 +680,7 @@ async function encryptForSenderKey({
);
const ourAddress = getOurAddress();
const senderKeyStore = new SenderKeys();
const message = Buffer.from(padMessage(contentMessage));
const message = Buffer.from(padMessage(new FIXMEU8(contentMessage)));
const ciphertextMessage = await window.textsecure.storage.protocol.enqueueSenderKeyJob(
ourAddress,