2022-08-18 20:44:53 +00:00
|
|
|
// 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';
|
2023-08-10 16:43:33 +00:00
|
|
|
import type { AciString } from '../types/ServiceId';
|
2022-08-18 20:44:53 +00:00
|
|
|
import * as log from '../logging/log';
|
2022-08-19 00:31:12 +00:00
|
|
|
import { isEnabled } from '../RemoteConfig';
|
2022-08-18 20:44:53 +00:00
|
|
|
import { isDirectConversation, isMe } from './whatTypeOfConversation';
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
export async function getServiceIdsForE164s(
|
2022-08-18 20:44:53 +00:00
|
|
|
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.
|
2023-10-31 19:00:25 +00:00
|
|
|
const acisAndAccessKeys = new Array<{ aci: AciString; accessKey: string }>();
|
2022-08-18 20:44:53 +00:00
|
|
|
|
|
|
|
for (const convo of window.ConversationController.getAll()) {
|
|
|
|
if (!isDirectConversation(convo.attributes) || isMe(convo.attributes)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
const aci = convo.getAci();
|
2022-08-18 20:44:53 +00:00
|
|
|
if (!aci) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
convo.deriveAccessKeyIfNeeded();
|
|
|
|
const accessKey = convo.get('accessKey');
|
|
|
|
if (!accessKey) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-10-31 19:00:25 +00:00
|
|
|
acisAndAccessKeys.push({ aci, accessKey });
|
2022-08-18 20:44:53 +00:00
|
|
|
}
|
|
|
|
|
2023-07-19 00:03:39 +00:00
|
|
|
const returnAcisWithoutUaks =
|
|
|
|
!isEnabled('cds.disableCompatibilityMode') &&
|
|
|
|
isEnabled('desktop.cdsi.returnAcisWithoutUaks');
|
2022-08-19 00:31:12 +00:00
|
|
|
|
2022-08-18 20:44:53 +00:00
|
|
|
log.info(
|
2023-10-31 19:00:25 +00:00
|
|
|
`getServiceIdsForE164s(${e164s}): acis=${acisAndAccessKeys.length} ` +
|
|
|
|
`accessKeys=${acisAndAccessKeys.length}`
|
2022-08-18 20:44:53 +00:00
|
|
|
);
|
2022-08-19 00:31:12 +00:00
|
|
|
return server.cdsLookup({
|
|
|
|
e164s,
|
2023-10-31 19:00:25 +00:00
|
|
|
acisAndAccessKeys,
|
2022-08-19 00:31:12 +00:00
|
|
|
returnAcisWithoutUaks,
|
|
|
|
});
|
2022-08-18 20:44:53 +00:00
|
|
|
}
|