Migrate schema to service ids

This commit is contained in:
Fedor Indutny 2023-08-16 22:54:39 +02:00 committed by Jamie Kyle
parent 71958f8a01
commit 8b0da36caa
258 changed files with 4795 additions and 2613 deletions

View file

@ -12,7 +12,7 @@ import {
getAttachmentUrlForPath,
getMessagePropStatus,
getSource,
getSourceUuid,
getSourceServiceId,
} from './message';
import {
getConversationByIdSelector,
@ -36,7 +36,7 @@ export type VoiceNoteForPlayback = {
url: string | undefined;
type: 'incoming' | 'outgoing';
source: string | undefined;
sourceUuid: ServiceIdString | undefined;
sourceServiceId: ServiceIdString | undefined;
isPlayed: boolean;
messageIdForLogging: string;
timestamp: number;
@ -60,15 +60,18 @@ export const selectVoiceNoteTitle = createSelector(
getIntl,
(ourNumber, ourAci, ourConversationId, conversationSelector, i18n) => {
return (
message: Pick<MessageAttributesType, 'type' | 'source' | 'sourceUuid'>
message: Pick<
MessageAttributesType,
'type' | 'source' | 'sourceServiceId'
>
) => {
const source = getSource(message, ourNumber);
const sourceUuid = getSourceUuid(message, ourAci);
const sourceServiceId = getSourceServiceId(message, ourAci);
const conversation =
!source && !sourceUuid
!source && !sourceServiceId
? conversationSelector(ourConversationId)
: conversationSelector(sourceUuid || source);
: conversationSelector(sourceServiceId || source);
return conversation.isMe ? i18n('icu:you') : conversation.title;
};
@ -103,7 +106,7 @@ export function extractVoiceNoteForPlayback(
messageIdForLogging: getMessageIdForLogging(message),
timestamp: message.timestamp,
source: message.source,
sourceUuid: message.sourceUuid,
sourceServiceId: message.sourceServiceId,
};
}

View file

@ -56,9 +56,11 @@ export const getByDistributionListConversationsStoppingSend = createSelector(
distributionListSelector(distributionId);
if (!currentDistribution) {
distributionData.serviceIdsNeedingVerification.forEach(uuid => {
conversationServiceIds.add(uuid);
});
distributionData.serviceIdsNeedingVerification.forEach(
serviceId => {
conversationServiceIds.add(serviceId);
}
);
return;
}
@ -72,7 +74,7 @@ export const getByDistributionListConversationsStoppingSend = createSelector(
name: currentDistribution.name,
},
contacts: distributionData.serviceIdsNeedingVerification.map(
uuid => conversationSelector(uuid)
serviceId => conversationSelector(serviceId)
),
});
}
@ -88,8 +90,8 @@ export const getByDistributionListConversationsStoppingSend = createSelector(
name: currentConversation.title,
}
: undefined,
contacts: Array.from(conversationServiceIds).map(uuid =>
conversationSelector(uuid)
contacts: Array.from(conversationServiceIds).map(serviceId =>
conversationSelector(serviceId)
),
});
}

View file

@ -37,7 +37,7 @@ import {
import type { ContactNameColorType } from '../../types/Colors';
import { ContactNameColors } from '../../types/Colors';
import type { AvatarDataType } from '../../types/Avatar';
import type { ServiceIdString } from '../../types/ServiceId';
import type { AciString, ServiceIdString } from '../../types/ServiceId';
import { isInSystemContacts } from '../../util/isInSystemContacts';
import { isSignalConnection } from '../../util/getSignalConnections';
import { sortByTitle } from '../../util/sortByTitle';
@ -109,10 +109,10 @@ export const getConversationLookup = createSelector(
}
);
export const getConversationsByUuid = createSelector(
export const getConversationsByServiceId = createSelector(
getConversations,
(state: ConversationsStateType): ConversationLookupType => {
return state.conversationsByUuid;
return state.conversationsByServiceId;
}
);
@ -687,7 +687,10 @@ export const getFilteredComposeGroups = createSelector(
ConversationType & {
membersCount: number;
disabledReason: undefined;
memberships: ReadonlyArray<unknown>;
memberships: ReadonlyArray<{
aci: AciString;
isAdmin: boolean;
}>;
}
> => {
return filterAndSortConversationsAlphabetically(
@ -801,13 +804,13 @@ export type GetConversationByIdType = (id?: string) => ConversationType;
export const getConversationSelector = createSelector(
getCachedSelectorForConversation,
getConversationLookup,
getConversationsByUuid,
getConversationsByServiceId,
getConversationsByE164,
getConversationsByGroupId,
(
selector: CachedConversationSelectorType,
byId: ConversationLookupType,
byUuid: ConversationLookupType,
byServiceId: ConversationLookupType,
byE164: ConversationLookupType,
byGroupId: ConversationLookupType
): GetConversationByIdType => {
@ -816,9 +819,12 @@ export const getConversationSelector = createSelector(
return selector(undefined);
}
const onUuid = getOwn(byUuid, id.toLowerCase ? id.toLowerCase() : id);
if (onUuid) {
return selector(onUuid);
const onServiceId = getOwn(
byServiceId,
id.toLowerCase ? id.toLowerCase() : id
);
if (onServiceId) {
return selector(onServiceId);
}
const onE164 = getOwn(byE164, id);
if (onE164) {
@ -847,11 +853,11 @@ export const getConversationByIdSelector = createSelector(
getOwn(conversationLookup, id)
);
export const getConversationByUuidSelector = createSelector(
getConversationsByUuid,
conversationsByUuid =>
(uuid: ServiceIdString): undefined | ConversationType =>
getOwn(conversationsByUuid, uuid)
export const getConversationByServiceIdSelector = createSelector(
getConversationsByServiceId,
conversationsByServiceId =>
(serviceId: ServiceIdString): undefined | ConversationType =>
getOwn(conversationsByServiceId, serviceId)
);
const getCachedConversationMemberColorsSelector = createSelector(
@ -880,7 +886,7 @@ const getCachedConversationMemberColorsSelector = createSelector(
[...sortedGroupMembers]
.sort((left, right) =>
String(left.uuid) > String(right.uuid) ? 1 : -1
String(left.serviceId) > String(right.serviceId) ? 1 : -1
)
.forEach((member, i) => {
contactNameColors.set(
@ -1017,7 +1023,7 @@ export const getConversationMessagesSelector = createSelector(
);
export const getInvitedContactsForNewlyCreatedGroup = createSelector(
getConversationsByUuid,
getConversationsByServiceId,
getConversations,
(
conversationLookup,
@ -1075,7 +1081,7 @@ export const getGroupAdminsSelector = createSelector(
const admins: Array<ConversationType> = [];
memberships.forEach(membership => {
if (membership.isAdmin) {
const admin = conversationSelector(membership.uuid);
const admin = conversationSelector(membership.aci);
admins.push(admin);
}
});
@ -1088,7 +1094,7 @@ export const getContactSelector = createSelector(
getConversationSelector,
conversationSelector => {
return (contactId: string) =>
pick(conversationSelector(contactId), 'id', 'title', 'uuid');
pick(conversationSelector(contactId), 'id', 'title', 'serviceId');
}
);

View file

@ -60,10 +60,10 @@ const isRemoteConfigBucketEnabled = (
config: Readonly<ConfigMapType>,
name: ConfigKeyType,
e164: string | undefined,
uuid: AciString | undefined
aci: AciString | undefined
): boolean => {
const flagValue = config[name]?.value;
return innerIsBucketValueEnabled(name, flagValue, e164, uuid);
return innerIsBucketValueEnabled(name, flagValue, e164, aci);
};
export const getRemoteConfig = createSelector(

View file

@ -216,16 +216,16 @@ export function getSourceDevice(
return sourceDevice || ourDeviceId;
}
export function getSourceUuid(
message: Pick<MessageAttributesType, 'type' | 'sourceUuid'>,
export function getSourceServiceId(
message: Pick<MessageAttributesType, 'type' | 'sourceServiceId'>,
ourAci: AciString | undefined
): ServiceIdString | undefined {
if (isIncoming(message)) {
return message.sourceUuid;
return message.sourceServiceId;
}
if (!isOutgoing(message)) {
log.warn(
'message.getSourceUuid: Called for non-incoming/non-outoing message'
'message.getSourceServiceId: Called for non-incoming/non-outoing message'
);
}
@ -247,13 +247,13 @@ export function getContactId(
}: GetContactOptions
): string | undefined {
const source = getSource(message, ourNumber);
const sourceUuid = getSourceUuid(message, ourAci);
const sourceServiceId = getSourceServiceId(message, ourAci);
if (!source && !sourceUuid) {
if (!source && !sourceServiceId) {
return ourConversationId;
}
const conversation = conversationSelector(sourceUuid || source);
const conversation = conversationSelector(sourceServiceId || source);
return conversation.id;
}
@ -268,13 +268,13 @@ export function getContact(
}: GetContactOptions
): ConversationType {
const source = getSource(message, ourNumber);
const sourceUuid = getSourceUuid(message, ourAci);
const sourceServiceId = getSourceServiceId(message, ourAci);
if (!source && !sourceUuid) {
if (!source && !sourceServiceId) {
return conversationSelector(ourConversationId);
}
return conversationSelector(sourceUuid || source);
return conversationSelector(sourceServiceId || source);
}
export function getConversation(
@ -341,7 +341,7 @@ export const extractHydratedMentions = (
.filter(BodyRange.isMention)
.map(range => {
const { conversationSelector } = options;
const conversation = conversationSelector(range.mentionUuid);
const conversation = conversationSelector(range.mentionAci);
return {
...range,
@ -484,7 +484,7 @@ const getPropsForStoryReplyContext = (
return undefined;
}
const contact = conversationSelector(storyReplyContext.authorUuid);
const contact = conversationSelector(storyReplyContext.authorAci);
const authorTitle = contact.firstName || contact.title;
const isFromMe = contact.id === ourConversationId;
@ -527,7 +527,7 @@ export const getPropsForQuote = (
const {
author,
authorUuid,
authorAci,
id: sentAt,
isViewOnce,
isGiftBadge: isTargetGiftBadge,
@ -536,7 +536,7 @@ export const getPropsForQuote = (
text = '',
} = quote;
const contact = conversationSelector(authorUuid || author);
const contact = conversationSelector(authorAci || author);
const authorId = contact.id;
const authorName = contact.name;
@ -960,7 +960,7 @@ function getPropsForPaymentEvent(
{ conversationSelector }: GetPropsForBubbleOptions
): Omit<PaymentEventNotificationPropsType, 'i18n'> {
return {
sender: conversationSelector(message.sourceUuid),
sender: conversationSelector(message.sourceServiceId),
conversation: getConversation(message, conversationSelector),
event: message.payment,
};
@ -1104,9 +1104,9 @@ function getPropsForTimerNotification(
);
}
const { expireTimer, fromSync, source, sourceUuid } = timerUpdate;
const { expireTimer, fromSync, source, sourceServiceId } = timerUpdate;
const disabled = !expireTimer;
const sourceId = sourceUuid || source;
const sourceId = sourceServiceId || source;
const { id: formattedContactId, title } = conversationSelector(sourceId);
// Pacify typescript
@ -1447,7 +1447,7 @@ function getPropsForChangeNumberNotification(
{ conversationSelector }: GetPropsForBubbleOptions
): ChangeNumberNotificationProps {
return {
sender: conversationSelector(message.sourceUuid),
sender: conversationSelector(message.sourceServiceId),
timestamp: message.sent_at,
};
}
@ -1500,7 +1500,7 @@ function getPropsForDeliveryIssue(
message: MessageWithUIFieldsType,
{ conversationSelector }: GetPropsForBubbleOptions
): DeliveryIssuePropsType {
const sender = conversationSelector(message.sourceUuid);
const sender = conversationSelector(message.sourceServiceId);
const conversation = getConversation(message, conversationSelector);
return {
@ -1631,7 +1631,7 @@ export function getPropsForEmbeddedContact(
regionCode,
getAbsoluteAttachmentPath: getAttachmentUrlForPath,
firstNumber,
uuid: accountSelector(firstNumber),
serviceId: accountSelector(firstNumber),
});
}

View file

@ -227,12 +227,12 @@ export const getMessageSearchResultSelector = createSelector(
return undefined;
}
const { conversationId, source, sourceUuid, type } = message;
const { conversationId, source, sourceServiceId, type } = message;
let from: ConversationType;
let to: ConversationType;
if (type === 'incoming') {
from = conversationSelector(sourceUuid || source);
from = conversationSelector(sourceServiceId || source);
to = conversationSelector(conversationId);
if (from === to) {
to = conversationSelector(ourConversationId);

View file

@ -68,14 +68,14 @@ function sortByRecencyAndUnread(
storyB: ConversationStoryType
): number {
if (
storyA.storyView.sender.uuid === SIGNAL_ACI &&
storyA.storyView.sender.serviceId === SIGNAL_ACI &&
storyA.storyView.isUnread
) {
return -1;
}
if (
storyB.storyView.sender.uuid === SIGNAL_ACI &&
storyB.storyView.sender.serviceId === SIGNAL_ACI &&
storyB.storyView.isUnread
) {
return 1;
@ -161,21 +161,24 @@ export function getStoryView(
ourConversationId: string | undefined,
story: StoryDataType
): StoryViewType {
const sender = pick(conversationSelector(story.sourceUuid || story.source), [
'acceptedMessageRequest',
'avatarPath',
'badges',
'color',
'firstName',
'hideStory',
'id',
'isMe',
'name',
'profileName',
'sharedGroupNames',
'title',
'uuid',
]);
const sender = pick(
conversationSelector(story.sourceServiceId || story.source),
[
'acceptedMessageRequest',
'avatarPath',
'badges',
'color',
'firstName',
'hideStory',
'id',
'isMe',
'name',
'profileName',
'sharedGroupNames',
'title',
'serviceId',
]
);
const {
attachment,
@ -213,7 +216,7 @@ export function getStoryView(
}
const messageIdForLogging = getMessageIdForLogging({
...pick(story, 'type', 'sourceUuid', 'sourceDevice'),
...pick(story, 'type', 'sourceServiceId', 'sourceDevice'),
sent_at: story.timestamp,
});
@ -242,9 +245,10 @@ export function getConversationStory(
ourConversationId: string | undefined,
story: StoryDataType
): ConversationStoryType {
const sender = pick(conversationSelector(story.sourceUuid || story.source), [
'id',
]);
const sender = pick(
conversationSelector(story.sourceServiceId || story.source),
['id']
);
const conversation = pick(conversationSelector(story.conversationId), [
'acceptedMessageRequest',
@ -295,7 +299,7 @@ export const getStoryReplies = createSelector(
const conversation =
reply.type === 'outgoing'
? me
: conversationSelector(reply.sourceUuid || reply.source);
: conversationSelector(reply.sourceServiceId || reply.source);
return {
author: getAvatarData(conversation),
@ -342,7 +346,7 @@ export const getStories = createSelector(
return;
}
const isSignalStory = story.sourceUuid === SIGNAL_ACI;
const isSignalStory = story.sourceServiceId === SIGNAL_ACI;
// if for some reason this story is already expired (bug)
// log it and skip it. Unless it's the onboarding story, that story
@ -352,7 +356,7 @@ export const getStories = createSelector(
(calculateExpirationTimestamp(story) ?? 0) < Date.now()
) {
const messageIdForLogging = getMessageIdForLogging({
...pick(story, 'type', 'sourceUuid', 'sourceDevice'),
...pick(story, 'type', 'sourceServiceId', 'sourceDevice'),
sent_at: story.timestamp,
});
log.warn('selectors/getStories: story already expired', {