Allow adding to a group by phone number
This commit is contained in:
parent
76a1a805ef
commit
9568d5792e
49 changed files with 1842 additions and 693 deletions
|
@ -7,12 +7,13 @@ import { OneTimeModalState } from '../../groups/toggleSelectedContactForGroupAdd
|
|||
export const defaultStartDirectConversationComposerState = {
|
||||
step: ComposerStep.StartDirectConversation as const,
|
||||
searchTerm: '',
|
||||
isFetchingUsername: false,
|
||||
uuidFetchState: {},
|
||||
};
|
||||
|
||||
export const defaultChooseGroupMembersComposerState = {
|
||||
step: ComposerStep.ChooseGroupMembers as const,
|
||||
searchTerm: '',
|
||||
uuidFetchState: {},
|
||||
groupAvatar: undefined,
|
||||
groupName: '',
|
||||
groupExpireTimer: 0,
|
||||
|
|
103
ts/test-both/helpers/fakeLookupConversationWithoutUuid.ts
Normal file
103
ts/test-both/helpers/fakeLookupConversationWithoutUuid.ts
Normal file
|
@ -0,0 +1,103 @@
|
|||
// Copyright 2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { useState } from 'react';
|
||||
|
||||
import type {
|
||||
UUIDFetchStateType,
|
||||
UUIDFetchStateKeyType,
|
||||
} from '../../util/uuidFetchState';
|
||||
import type { lookupConversationWithoutUuid } from '../../util/lookupConversationWithoutUuid';
|
||||
import { sleep } from '../../util/sleep';
|
||||
import * as durations from '../../util/durations';
|
||||
import type { ConversationType } from '../../state/ducks/conversations';
|
||||
import { getDefaultConversation } from './getDefaultConversation';
|
||||
|
||||
const VALID_IDENTIFIERS = new Set<UUIDFetchStateKeyType>([
|
||||
'e164:+12125551234',
|
||||
'username:bobross',
|
||||
]);
|
||||
|
||||
export function makeFakeLookupConversationWithoutUuid(
|
||||
saveConversation?: (convo: ConversationType) => void
|
||||
): typeof lookupConversationWithoutUuid {
|
||||
const cache = new Map<UUIDFetchStateKeyType, ConversationType>();
|
||||
|
||||
return async options => {
|
||||
const identifier: UUIDFetchStateKeyType =
|
||||
options.type === 'e164'
|
||||
? `e164:${options.e164}`
|
||||
: `username:${options.username}`;
|
||||
|
||||
let result = cache.get(identifier);
|
||||
if (result) {
|
||||
return result.id;
|
||||
}
|
||||
|
||||
if (VALID_IDENTIFIERS.has(identifier) && saveConversation) {
|
||||
result = getDefaultConversation({
|
||||
// We don't really know anything about the contact
|
||||
firstName: undefined,
|
||||
avatarPath: undefined,
|
||||
name: undefined,
|
||||
profileName: undefined,
|
||||
|
||||
...(options.type === 'e164'
|
||||
? {
|
||||
title: options.e164,
|
||||
e164: options.e164,
|
||||
phoneNumber: options.e164,
|
||||
}
|
||||
: {
|
||||
title: `@${options.username}`,
|
||||
username: options.username,
|
||||
}),
|
||||
});
|
||||
cache.set(identifier, result);
|
||||
|
||||
saveConversation(result);
|
||||
}
|
||||
|
||||
options.setIsFetchingUUID(identifier, true);
|
||||
|
||||
await sleep(durations.SECOND);
|
||||
|
||||
options.setIsFetchingUUID(identifier, false);
|
||||
|
||||
if (!result) {
|
||||
options.showUserNotFoundModal(
|
||||
options.type === 'username'
|
||||
? options
|
||||
: {
|
||||
type: 'phoneNumber',
|
||||
phoneNumber: options.phoneNumber,
|
||||
}
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return result.id;
|
||||
};
|
||||
}
|
||||
|
||||
type SetIsFetchingUUIDType = (
|
||||
identifier: UUIDFetchStateKeyType,
|
||||
isFetching: boolean
|
||||
) => void;
|
||||
|
||||
export function useUuidFetchState(
|
||||
initial: UUIDFetchStateType = {}
|
||||
): [UUIDFetchStateType, SetIsFetchingUUIDType] {
|
||||
const [uuidFetchState, setUuidFetchState] = useState(initial);
|
||||
|
||||
const setIsFetchingUUID: SetIsFetchingUUIDType = (key, value) => {
|
||||
setUuidFetchState(prev => {
|
||||
return {
|
||||
...prev,
|
||||
[key]: value,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
return [uuidFetchState, setIsFetchingUUID];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue