Include ACI+Access Keys pairs with CDSI requests
This commit is contained in:
parent
13046dc020
commit
757af2cbbe
17 changed files with 145 additions and 144 deletions
45
ts/util/getUuidsForE164s.ts
Normal file
45
ts/util/getUuidsForE164s.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
// Copyright 2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { CDSResponseType } from '../textsecure/cds/Types.d';
|
||||
import type { WebAPIType } from '../textsecure/WebAPI';
|
||||
import type { UUIDStringType } from '../types/UUID';
|
||||
import * as log from '../logging/log';
|
||||
import { isDirectConversation, isMe } from './whatTypeOfConversation';
|
||||
|
||||
export async function getUuidsForE164s(
|
||||
server: Pick<WebAPIType, 'cdsLookup'>,
|
||||
e164s: ReadonlyArray<string>
|
||||
): Promise<CDSResponseType> {
|
||||
// Note: these have no relationship to supplied e164s. We just provide
|
||||
// all available information to the server so that it could return as many
|
||||
// ACI+PNI+E164 matches as possible.
|
||||
const acis = new Array<UUIDStringType>();
|
||||
const accessKeys = new Array<string>();
|
||||
|
||||
for (const convo of window.ConversationController.getAll()) {
|
||||
if (!isDirectConversation(convo.attributes) || isMe(convo.attributes)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const aci = convo.getUuid();
|
||||
if (!aci) {
|
||||
continue;
|
||||
}
|
||||
|
||||
convo.deriveAccessKeyIfNeeded();
|
||||
const accessKey = convo.get('accessKey');
|
||||
if (!accessKey) {
|
||||
continue;
|
||||
}
|
||||
|
||||
acis.push(aci.toString());
|
||||
accessKeys.push(accessKey);
|
||||
}
|
||||
|
||||
log.info(
|
||||
`getUuidsForE164s(${e164s}): acis=${acis.length} ` +
|
||||
`accessKeys=${accessKeys.length}`
|
||||
);
|
||||
return server.cdsLookup({ e164s, acis, accessKeys });
|
||||
}
|
|
@ -12,6 +12,7 @@ import { downloadAttachment } from './downloadAttachment';
|
|||
import { generateSecurityNumber } from './safetyNumber';
|
||||
import { getStringForProfileChange } from './getStringForProfileChange';
|
||||
import { getTextWithMentions } from './getTextWithMentions';
|
||||
import { getUuidsForE164s } from './getUuidsForE164s';
|
||||
import { getUserAgent } from './getUserAgent';
|
||||
import { hasExpired } from './hasExpired';
|
||||
import {
|
||||
|
@ -81,4 +82,5 @@ export {
|
|||
toWebSafeBase64,
|
||||
zkgroup,
|
||||
expirationTimer,
|
||||
getUuidsForE164s,
|
||||
};
|
||||
|
|
|
@ -13,6 +13,7 @@ import { HTTPError } from '../textsecure/Errors';
|
|||
import { showToast } from './showToast';
|
||||
import { strictAssert } from './assert';
|
||||
import type { UUIDFetchStateKeyType } from './uuidFetchState';
|
||||
import { getUuidsForE164s } from './getUuidsForE164s';
|
||||
|
||||
export type LookupConversationWithoutUuidActionsType = Readonly<{
|
||||
lookupConversationWithoutUuid: typeof lookupConversationWithoutUuid;
|
||||
|
@ -62,19 +63,22 @@ export async function lookupConversationWithoutUuid(
|
|||
const { showUserNotFoundModal, setIsFetchingUUID } = options;
|
||||
setIsFetchingUUID(identifier, true);
|
||||
|
||||
const { messaging } = window.textsecure;
|
||||
if (!messaging) {
|
||||
throw new Error('messaging is not available!');
|
||||
const { server } = window.textsecure;
|
||||
if (!server) {
|
||||
throw new Error('server is not available!');
|
||||
}
|
||||
|
||||
try {
|
||||
let conversationId: string | undefined;
|
||||
if (options.type === 'e164') {
|
||||
const serverLookup = await messaging.getUuidsForE164s([options.e164]);
|
||||
const serverLookup = await getUuidsForE164s(server, [options.e164]);
|
||||
|
||||
if (serverLookup[options.e164]) {
|
||||
const maybePair = serverLookup.get(options.e164);
|
||||
|
||||
if (maybePair) {
|
||||
const convo = window.ConversationController.maybeMergeContacts({
|
||||
aci: serverLookup[options.e164] || undefined,
|
||||
aci: maybePair.aci,
|
||||
pni: maybePair.pni,
|
||||
e164: options.e164,
|
||||
reason: 'startNewConversationWithoutUuid(e164)',
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue