Introduce Service Id Types

Co-authored-by: Scott Nonnenberg <scott@signal.org>
This commit is contained in:
Fedor Indutny 2023-08-10 18:43:33 +02:00 committed by Jamie Kyle
parent 414c0a58d3
commit 366b875fd2
269 changed files with 5832 additions and 5550 deletions

View file

@ -7,7 +7,7 @@ import type {
UUIDFetchStateType,
UUIDFetchStateKeyType,
} from '../../util/uuidFetchState';
import type { lookupConversationWithoutUuid } from '../../util/lookupConversationWithoutUuid';
import type { lookupConversationWithoutServiceId } from '../../util/lookupConversationWithoutServiceId';
import { sleep } from '../../util/sleep';
import * as durations from '../../util/durations';
import type { ConversationType } from '../../state/ducks/conversations';
@ -18,9 +18,9 @@ const VALID_IDENTIFIERS = new Set<UUIDFetchStateKeyType>([
'username:bobross',
]);
export function makeFakeLookupConversationWithoutUuid(
export function makeFakeLookupConversationWithoutServiceId(
saveConversation?: (convo: ConversationType) => void
): typeof lookupConversationWithoutUuid {
): typeof lookupConversationWithoutServiceId {
const cache = new Map<UUIDFetchStateKeyType, ConversationType>();
return async options => {

View file

@ -3,9 +3,11 @@
import casual from 'casual';
import { sample } from 'lodash';
import { v4 as generateUuid } from 'uuid';
import type { ConversationType } from '../../state/ducks/conversations';
import type { UUIDStringType } from '../../types/UUID';
import { UUID } from '../../types/UUID';
import type { ServiceIdString } from '../../types/ServiceId';
import { generateAci } from '../../types/ServiceId';
import type { GroupListItemConversationType } from '../../components/conversationList/GroupListItem';
import { getRandomColor } from './getRandomColor';
import { ConversationColors } from '../../types/Colors';
@ -32,14 +34,14 @@ export function getDefaultConversation(
conversationColor: ConversationColors[0],
color: getRandomColor(),
firstName,
id: UUID.generate().toString(),
id: generateUuid(),
isMe: false,
lastUpdated: casual.unix_time,
markedUnread: Boolean(overrideProps.markedUnread),
sharedGroupNames: [],
title: `${firstName} ${lastName}`,
titleNoDefault: `${firstName} ${lastName}`,
uuid: UUID.generate().toString(),
uuid: generateAci(),
...overrideProps,
type: 'direct' as const,
acknowledgedGroupNameCollisions: undefined,
@ -63,7 +65,7 @@ export function getDefaultGroup(
overrideProps: Partial<ConversationType> = {}
): ConversationType {
const memberships = Array.from(Array(casual.integer(1, 20)), () => ({
uuid: UUID.generate().toString(),
uuid: generateAci(),
isAdmin: Boolean(casual.coin_flip),
}));
@ -75,10 +77,10 @@ export function getDefaultGroup(
color: getRandomColor(),
conversationColor: ConversationColors[0],
groupDescription: casual.sentence,
groupId: UUID.generate().toString(),
groupId: generateUuid(),
groupLink: casual.url,
groupVersion: 2,
id: UUID.generate().toString(),
id: generateUuid(),
isMe: false,
lastUpdated: casual.unix_time,
markedUnread: Boolean(overrideProps.markedUnread),
@ -86,7 +88,7 @@ export function getDefaultGroup(
memberships,
sharedGroupNames: [],
title: casual.title,
uuid: UUID.generate().toString(),
uuid: generateAci(),
acknowledgedGroupNameCollisions: {},
storySendMode: StorySendMode.IfActive,
...overrideProps,
@ -96,8 +98,8 @@ export function getDefaultGroup(
export function getDefaultConversationWithUuid(
overrideProps: Partial<ConversationType> = {},
uuid: UUIDStringType = UUID.generate().toString()
): ConversationType & { uuid: UUIDStringType } {
uuid: ServiceIdString = generateAci()
): ConversationType & { uuid: ServiceIdString } {
return {
...getDefaultConversation(overrideProps),
uuid,

View file

@ -6,7 +6,8 @@ import casual from 'casual';
import type { StoryDistributionListDataType } from '../../state/ducks/storyDistributionLists';
import type { StoryDistributionListWithMembersDataType } from '../../types/Stories';
import { MY_STORY_ID } from '../../types/Stories';
import { UUID } from '../../types/UUID';
import { generateStoryDistributionId } from '../../types/StoryDistributionId';
import { generateAci } from '../../types/ServiceId';
import { getDefaultConversation } from './getDefaultConversation';
export function getFakeDistributionListsWithMembers(): Array<StoryDistributionListWithMembersDataType> {
@ -34,10 +35,10 @@ export function getFakeDistributionLists(): Array<StoryDistributionListDataType>
export function getFakeDistributionList(): StoryDistributionListDataType {
return {
allowsReplies: Boolean(casual.coin_flip),
id: UUID.generate().toString(),
id: generateStoryDistributionId(),
isBlockList: false,
memberUuids: Array.from(Array(casual.integer(3, 12)), () =>
UUID.generate().toString()
memberServiceIds: Array.from(Array(casual.integer(3, 12)), () =>
generateAci()
),
name: casual.title,
};
@ -48,7 +49,7 @@ export function getMyStories(): StoryDistributionListDataType {
allowsReplies: true,
id: MY_STORY_ID,
isBlockList: true,
memberUuids: [],
memberServiceIds: [],
name: MY_STORY_ID,
};
}

View file

@ -2,6 +2,7 @@
// SPDX-License-Identifier: AGPL-3.0-only
import casual from 'casual';
import { v4 as generateUuid } from 'uuid';
import type { AttachmentType } from '../../types/Attachment';
import type { ConversationType } from '../../state/ducks/conversations';
@ -11,7 +12,6 @@ import type {
StoryViewType,
} from '../../types/Stories';
import * as durations from '../../util/durations';
import { UUID } from '../../types/UUID';
import { getDefaultConversation } from './getDefaultConversation';
import { fakeAttachment, fakeThumbnail } from './fakeAttachment';
import { MY_STORY_ID, ResolvedSendStatus } from '../../types/Stories';
@ -28,7 +28,7 @@ export function getFakeMyStory(id?: string, name?: string): MyStoryType {
const storyCount = casual.integer(2, 6);
return {
id: id || UUID.generate().toString(),
id: id || generateUuid(),
name: name || id === MY_STORY_ID ? 'My Stories' : casual.catch_phrase,
reducedSendStatus: ResolvedSendStatus.Sent,
stories: Array.from(Array(storyCount), () => ({
@ -45,7 +45,7 @@ export function getFakeStoryView(
): StoryViewType {
const sender = getDefaultConversation();
const messageId = UUID.generate().toString();
const messageId = generateUuid();
return {
attachment: getAttachmentWithThumbnail(