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

@ -4,7 +4,7 @@
import type { Database } from '@signalapp/better-sqlite3';
import type { LoggerType } from '../../types/Logging';
import { isValidUuid } from '../../types/UUID';
import { isValidUuid } from '../../util/isValidUuid';
import { assertSync } from '../../util/assert';
import Helpers from '../../textsecure/Helpers';
import { createOrUpdate, getById, removeById } from '../util';

View file

@ -5,7 +5,8 @@ import type { Database } from '@signalapp/better-sqlite3';
import { omit } from 'lodash';
import type { LoggerType } from '../../types/Logging';
import type { UUIDStringType } from '../../types/UUID';
import type { AciString, ServiceIdString } from '../../types/ServiceId';
import { normalizeAci } from '../../types/ServiceId';
import { isNotNil } from '../../util/isNotNil';
import { assertDev } from '../../util/assert';
import {
@ -96,7 +97,7 @@ export default function updateToSchemaVersion43(
const newValue = oldValue
.map(member => {
const uuid: UUIDStringType = getConversationUuid.get({
const uuid: ServiceIdString = getConversationUuid.get({
conversationId: member.conversationId,
});
if (!uuid) {
@ -117,7 +118,7 @@ export default function updateToSchemaVersion43(
return updated;
}
const addedByUserId: UUIDStringType | undefined =
const addedByUserId: ServiceIdString | undefined =
getConversationUuid.get({
conversationId: member.addedByUserId,
});
@ -227,7 +228,7 @@ export default function updateToSchemaVersion43(
if (groupV2Change) {
assertDev(result.groupV2Change, 'Pacify typescript');
const from: UUIDStringType | undefined = getConversationUuid.get({
const from: AciString | undefined = getConversationUuid.get({
conversationId: groupV2Change.from,
});
@ -262,7 +263,7 @@ export default function updateToSchemaVersion43(
}
changedDetails = true;
const newValue: UUIDStringType | null = getConversationUuid.get({
const newValue: ServiceIdString | null = getConversationUuid.get({
conversationId: oldValue,
});
if (key === 'inviter' && !newValue) {
@ -302,7 +303,7 @@ export default function updateToSchemaVersion43(
}
if (sourceUuid) {
const newValue: UUIDStringType | null = getConversationUuid.get({
const newValue: ServiceIdString | null = getConversationUuid.get({
conversationId: sourceUuid,
});
@ -317,7 +318,7 @@ export default function updateToSchemaVersion43(
if (invitedGV2Members) {
const newMembers = invitedGV2Members
.map(({ addedByUserId, conversationId }, i) => {
const uuid: UUIDStringType | null = getConversationUuid.get({
const uuid: ServiceIdString | null = getConversationUuid.get({
conversationId,
});
const oldMember =
@ -341,7 +342,7 @@ export default function updateToSchemaVersion43(
return newMember;
}
const newAddedBy: UUIDStringType | null = getConversationUuid.get({
const newAddedBy: ServiceIdString | null = getConversationUuid.get({
conversationId: addedByUserId,
});
if (!newAddedBy) {
@ -350,7 +351,7 @@ export default function updateToSchemaVersion43(
return {
...newMember,
addedByUserId: newAddedBy,
addedByUserId: normalizeAci(newAddedBy, 'migration-43'),
};
})
.filter(isNotNil);

View file

@ -4,7 +4,7 @@
import type { Database } from '@signalapp/better-sqlite3';
import type { LoggerType } from '../../types/Logging';
import type { UUIDStringType } from '../../types/UUID';
import type { ServiceIdString } from '../../types/ServiceId';
import { jsonToObject } from '../util';
import type { EmptyQuery } from '../util';
import type { ConversationType } from '../Interface';
@ -21,7 +21,7 @@ export default function updateToSchemaVersion53(
type LegacyConversationType = {
id: string;
groupId: string;
bannedMembersV2?: Array<UUIDStringType>;
bannedMembersV2?: Array<ServiceIdString>;
};
const updateConversationStmt = db.prepare(

View file

@ -3,9 +3,9 @@
import type { Database } from '@signalapp/better-sqlite3';
import { keyBy } from 'lodash';
import { v4 as generateUuid } from 'uuid';
import type { LoggerType } from '../../types/Logging';
import { UUID } from '../../types/UUID';
import {
getSchemaVersion,
getUserVersion,
@ -965,7 +965,7 @@ function updateToSchemaVersion20(
for (const row of allConversations) {
const oldId = row.id;
const newId = UUID.generate().toString();
const newId = generateUuid();
allConversationsByOldId[oldId].id = newId;
const patchObj: { id: string; e164?: string; groupId?: string } = {
id: newId,
@ -1022,7 +1022,7 @@ function updateToSchemaVersion20(
} else {
// We didn't previously have a private conversation for this member,
// we need to create one
const id = UUID.generate().toString();
const id = generateUuid();
const updatedConversation = {
id,
e164: m,