Introduce Service Id Types
Co-authored-by: Scott Nonnenberg <scott@signal.org>
This commit is contained in:
parent
414c0a58d3
commit
366b875fd2
269 changed files with 5832 additions and 5550 deletions
55
ts/util/getServiceIdsForE164s.ts
Normal file
55
ts/util/getServiceIdsForE164s.ts
Normal file
|
@ -0,0 +1,55 @@
|
|||
// 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 { AciString } from '../types/ServiceId';
|
||||
import * as log from '../logging/log';
|
||||
import { isEnabled } from '../RemoteConfig';
|
||||
import { isDirectConversation, isMe } from './whatTypeOfConversation';
|
||||
|
||||
export async function getServiceIdsForE164s(
|
||||
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<AciString>();
|
||||
const accessKeys = new Array<string>();
|
||||
|
||||
for (const convo of window.ConversationController.getAll()) {
|
||||
if (!isDirectConversation(convo.attributes) || isMe(convo.attributes)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const aci = convo.getAci();
|
||||
if (!aci) {
|
||||
continue;
|
||||
}
|
||||
|
||||
convo.deriveAccessKeyIfNeeded();
|
||||
const accessKey = convo.get('accessKey');
|
||||
if (!accessKey) {
|
||||
continue;
|
||||
}
|
||||
|
||||
acis.push(aci);
|
||||
accessKeys.push(accessKey);
|
||||
}
|
||||
|
||||
const returnAcisWithoutUaks =
|
||||
!isEnabled('cds.disableCompatibilityMode') &&
|
||||
isEnabled('desktop.cdsi.returnAcisWithoutUaks');
|
||||
|
||||
log.info(
|
||||
`getServiceIdsForE164s(${e164s}): acis=${acis.length} ` +
|
||||
`accessKeys=${accessKeys.length}`
|
||||
);
|
||||
return server.cdsLookup({
|
||||
e164s,
|
||||
acis,
|
||||
accessKeys,
|
||||
returnAcisWithoutUaks,
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue