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

@ -15,10 +15,10 @@ import { assertDev, softAssert } from '../util/assert';
import { mapObjectWithSpec } from '../util/mapObjectWithSpec';
import type { ObjectMappingSpecType } from '../util/mapObjectWithSpec';
import { cleanDataForIpc } from './cleanDataForIpc';
import type { UUIDStringType } from '../types/UUID';
import type { AciString } from '../types/ServiceId';
import createTaskWithTimeout from '../textsecure/TaskWithTimeout';
import * as log from '../logging/log';
import { isValidUuid } from '../types/UUID';
import { isValidUuid } from '../util/isValidUuid';
import * as Errors from '../types/errors';
import type { StoredJob } from '../jobs/types';
@ -539,7 +539,7 @@ async function saveMessage(
options: {
jobToInsert?: Readonly<StoredJob>;
forceSave?: boolean;
ourUuid: UUIDStringType;
ourAci: AciString;
}
): Promise<string> {
const id = await channels.saveMessage(_cleanMessageData(data), {
@ -557,7 +557,7 @@ async function saveMessage(
async function saveMessages(
arrayOfMessages: ReadonlyArray<MessageType>,
options: { forceSave?: boolean; ourUuid: UUIDStringType }
options: { forceSave?: boolean; ourAci: AciString }
): Promise<void> {
await channels.saveMessages(
arrayOfMessages.map(message => _cleanMessageData(message)),

View file

@ -13,7 +13,8 @@ import type { StorageAccessType } from '../types/Storage.d';
import type { AttachmentType } from '../types/Attachment';
import type { BytesToStrings } from '../types/Util';
import type { QualifiedAddressStringType } from '../types/QualifiedAddress';
import type { UUIDStringType } from '../types/UUID';
import type { StoryDistributionIdString } from '../types/StoryDistributionId';
import type { AciString, ServiceIdString } from '../types/ServiceId';
import type { BadgeType } from '../badges/types';
import type { RemoveAllConfiguration } from '../types/RemoveAllConfiguration';
import type { LoggerType } from '../types/Logging';
@ -84,7 +85,7 @@ export type EmojiType = {
export type IdentityKeyType = {
firstUse: boolean;
id: UUIDStringType | `conversation:${string}`;
id: ServiceIdString | `conversation:${string}`;
nonblockingApproval: boolean;
publicKey: Uint8Array;
timestamp: number;
@ -92,7 +93,7 @@ export type IdentityKeyType = {
};
export type StoredIdentityKeyType = {
firstUse: boolean;
id: UUIDStringType | `conversation:${string}`;
id: ServiceIdString | `conversation:${string}`;
nonblockingApproval: boolean;
publicKey: string;
timestamp: number;
@ -116,7 +117,7 @@ export type MessageTypeUnhydrated = {
json: string;
};
export type PreKeyIdType = `${UUIDStringType}:${number}`;
export type PreKeyIdType = `${ServiceIdString}:${number}`;
export type KyberPreKeyType = {
id: PreKeyIdType;
@ -125,7 +126,7 @@ export type KyberPreKeyType = {
isConfirmed: boolean;
isLastResort: boolean;
keyId: number;
ourUuid: UUIDStringType;
ourUuid: ServiceIdString;
};
export type StoredKyberPreKeyType = KyberPreKeyType & {
data: string;
@ -135,7 +136,7 @@ export type PreKeyType = {
createdAt: number;
keyId: number;
ourUuid: UUIDStringType;
ourUuid: ServiceIdString;
privateKey: Uint8Array;
publicKey: Uint8Array;
};
@ -171,7 +172,7 @@ export type SentProtoType = {
export type SentProtoWithMessageIdsType = SentProtoType & {
messageIds: Array<string>;
};
export type SentRecipientsType = Record<string, Array<number>>;
export type SentRecipientsType = Record<ServiceIdString, Array<number>>;
export type SentMessagesType = Array<string>;
// These two are for test only
@ -198,8 +199,8 @@ export type SenderKeyType = {
export type SenderKeyIdType = SenderKeyType['id'];
export type SessionType = {
id: QualifiedAddressStringType;
ourUuid: UUIDStringType;
uuid: UUIDStringType;
ourUuid: ServiceIdString;
uuid: ServiceIdString;
conversationId: string;
deviceId: number;
record: string;
@ -209,8 +210,8 @@ export type SessionIdType = SessionType['id'];
export type SignedPreKeyType = {
confirmed: boolean;
created_at: number;
ourUuid: UUIDStringType;
id: `${UUIDStringType}:${number}`;
ourUuid: ServiceIdString;
id: `${ServiceIdString}:${number}`;
keyId: number;
privateKey: Uint8Array;
publicKey: Uint8Array;
@ -218,8 +219,8 @@ export type SignedPreKeyType = {
export type StoredSignedPreKeyType = {
confirmed: boolean;
created_at: number;
ourUuid: UUIDStringType;
id: `${UUIDStringType}:${number}`;
ourUuid: ServiceIdString;
id: `${ServiceIdString}:${number}`;
keyId: number;
privateKey: string;
publicKey: string;
@ -304,10 +305,10 @@ export type UnprocessedType = {
messageAgeSec?: number;
source?: string;
sourceUuid?: UUIDStringType;
sourceUuid?: ServiceIdString;
sourceDevice?: number;
destinationUuid?: string;
updatedPni?: string;
destinationUuid?: ServiceIdString;
updatedPni?: ServiceIdString;
serverGuid?: string;
serverTimestamp?: number;
decrypted?: string;
@ -318,7 +319,7 @@ export type UnprocessedType = {
export type UnprocessedUpdateType = {
source?: string;
sourceUuid?: UUIDStringType;
sourceUuid?: ServiceIdString;
sourceDevice?: number;
serverGuid?: string;
serverTimestamp?: number;
@ -333,7 +334,7 @@ export type ConversationMessageStatsType = {
export type DeleteSentProtoRecipientOptionsType = Readonly<{
timestamp: number;
recipientUuid: string;
recipientServiceId: ServiceIdString;
deviceId: number;
}>;
@ -342,7 +343,7 @@ export type DeleteSentProtoRecipientResultType = Readonly<{
}>;
export type StoryDistributionType = Readonly<{
id: UUIDStringType;
id: StoryDistributionIdString;
name: string;
deletedAtTimestamp?: number;
allowsReplies: boolean;
@ -351,17 +352,17 @@ export type StoryDistributionType = Readonly<{
}> &
StorageServiceFieldsType;
export type StoryDistributionMemberType = Readonly<{
listId: UUIDStringType;
uuid: UUIDStringType;
listId: StoryDistributionIdString;
uuid: ServiceIdString;
}>;
export type StoryDistributionWithMembersType = Readonly<
{
members: Array<UUIDStringType>;
members: Array<ServiceIdString>;
} & StoryDistributionType
>;
export type StoryReadType = Readonly<{
authorId: UUIDStringType;
authorId: ServiceIdString;
conversationId: string;
storyId: string;
storyReadDate: number;
@ -433,17 +434,17 @@ export type DataInterface = {
removeKyberPreKeyById: (
id: PreKeyIdType | Array<PreKeyIdType>
) => Promise<void>;
removeKyberPreKeysByUuid: (uuid: UUIDStringType) => Promise<void>;
removeKyberPreKeysByServiceId: (serviceId: ServiceIdString) => Promise<void>;
removeAllKyberPreKeys: () => Promise<void>;
removePreKeyById: (id: PreKeyIdType | Array<PreKeyIdType>) => Promise<void>;
removePreKeysByUuid: (uuid: UUIDStringType) => Promise<void>;
removePreKeysByServiceId: (serviceId: ServiceIdString) => Promise<void>;
removeAllPreKeys: () => Promise<void>;
removeSignedPreKeyById: (
id: SignedPreKeyIdType | Array<SignedPreKeyIdType>
) => Promise<void>;
removeSignedPreKeysByUuid: (uuid: UUIDStringType) => Promise<void>;
removeSignedPreKeysByServiceId: (serviceId: ServiceIdString) => Promise<void>;
removeAllSignedPreKeys: () => Promise<void>;
removeAllItems: () => Promise<void>;
@ -466,7 +467,7 @@ export type DataInterface = {
deleteSentProtoByMessageId: (messageId: string) => Promise<void>;
insertProtoRecipients: (options: {
id: number;
recipientUuid: string;
recipientServiceId: ServiceIdString;
deviceIds: Array<number>;
}) => Promise<void>;
deleteSentProtoRecipient: (
@ -476,7 +477,7 @@ export type DataInterface = {
) => Promise<DeleteSentProtoRecipientResultType>;
getSentProtoByRecipient: (options: {
now: number;
recipientUuid: string;
recipientServiceId: ServiceIdString;
timestamp: number;
}) => Promise<SentProtoWithMessageIdsType | undefined>;
removeAllSentProtos: () => Promise<void>;
@ -495,7 +496,7 @@ export type DataInterface = {
bulkAddSessions: (array: Array<SessionType>) => Promise<void>;
removeSessionById: (id: SessionIdType) => Promise<void>;
removeSessionsByConversation: (conversationId: string) => Promise<void>;
removeSessionsByUUID: (uuid: UUIDStringType) => Promise<void>;
removeSessionsByServiceId: (serviceId: ServiceIdString) => Promise<void>;
removeAllSessions: () => Promise<void>;
getAllSessions: () => Promise<Array<SessionType>>;
@ -519,8 +520,8 @@ export type DataInterface = {
getAllConversations: () => Promise<Array<ConversationType>>;
getAllConversationIds: () => Promise<Array<string>>;
getAllGroupsInvolvingUuid: (
id: UUIDStringType
getAllGroupsInvolvingServiceId: (
serviceId: ServiceIdString
) => Promise<Array<ConversationType>>;
getMessageCount: (conversationId?: string) => Promise<number>;
@ -530,12 +531,12 @@ export type DataInterface = {
options: {
jobToInsert?: StoredJob;
forceSave?: boolean;
ourUuid: UUIDStringType;
ourAci: AciString;
}
) => Promise<string>;
saveMessages: (
arrayOfMessages: ReadonlyArray<MessageType>,
options: { forceSave?: boolean; ourUuid: UUIDStringType }
options: { forceSave?: boolean; ourAci: AciString }
) => Promise<void>;
removeMessage: (id: string) => Promise<void>;
removeMessages: (ids: ReadonlyArray<string>) => Promise<void>;
@ -578,13 +579,13 @@ export type DataInterface = {
storyId?: string;
}) => Promise<Array<ReactionResultType>>;
markReactionAsRead: (
targetAuthorUuid: string,
targetAuthorServiceId: ServiceIdString,
targetTimestamp: number
) => Promise<ReactionType | undefined>;
removeReactionFromConversation: (reaction: {
emoji: string;
fromId: string;
targetAuthorUuid: string;
targetAuthorServiceId: ServiceIdString;
targetTimestamp: number;
}) => Promise<void>;
addReaction: (reactionObj: ReactionType) => Promise<void>;
@ -592,7 +593,7 @@ export type DataInterface = {
_removeAllReactions: () => Promise<void>;
getMessageBySender: (options: {
source?: string;
sourceUuid?: UUIDStringType;
sourceUuid?: ServiceIdString;
sourceDevice?: number;
sent_at: number;
}) => Promise<MessageType | undefined>;
@ -617,7 +618,7 @@ export type DataInterface = {
// getOlderMessagesByConversation is JSON on server, full message on Client
getAllStories: (options: {
conversationId?: string;
sourceUuid?: UUIDStringType;
sourceUuid?: ServiceIdString;
}) => Promise<GetAllStoriesResultType>;
// getNewerMessagesByConversation is JSON on server, full message on Client
getMessageMetricsForConversation: (options: {
@ -629,7 +630,6 @@ export type DataInterface = {
getConversationMessageStats: (options: {
conversationId: string;
includeStoryReplies: boolean;
ourUuid: UUIDStringType;
}) => Promise<ConversationMessageStatsType>;
getLastConversationMessage(options: {
conversationId: string;
@ -642,7 +642,7 @@ export type DataInterface = {
}): Promise<MessageType | undefined>;
getCallHistory(
callId: string,
peerId: string
peerId: ServiceIdString | string
): Promise<CallHistoryDetails | undefined>;
getCallHistoryGroupsCount(filter: CallHistoryFilter): Promise<number>;
getCallHistoryGroups(
@ -667,7 +667,7 @@ export type DataInterface = {
) => Promise<string | null>;
saveEditedMessage: (
mainMessage: MessageType,
ourUuid: UUIDStringType,
ourAci: AciString,
opts: EditedMessageType
) => Promise<void>;
getUnprocessedCount: () => Promise<number>;
@ -767,25 +767,25 @@ export type DataInterface = {
modifyStoryDistributionMembers(
listId: string,
options: {
toAdd: Array<UUIDStringType>;
toRemove: Array<UUIDStringType>;
toAdd: Array<ServiceIdString>;
toRemove: Array<ServiceIdString>;
}
): Promise<void>;
modifyStoryDistributionWithMembers(
distribution: StoryDistributionType,
options: {
toAdd: Array<UUIDStringType>;
toRemove: Array<UUIDStringType>;
toAdd: Array<ServiceIdString>;
toRemove: Array<ServiceIdString>;
}
): Promise<void>;
deleteStoryDistribution(id: UUIDStringType): Promise<void>;
deleteStoryDistribution(id: StoryDistributionIdString): Promise<void>;
_getAllStoryReads(): Promise<Array<StoryReadType>>;
_deleteAllStoryReads(): Promise<void>;
addNewStoryRead(read: StoryReadType): Promise<void>;
getLastStoryReadsForAuthor(options: {
authorId: UUIDStringType;
conversationId?: UUIDStringType;
authorId: ServiceIdString;
conversationId?: string;
limit?: number;
}): Promise<Array<StoryReadType>>;
countStoryReadsByConversation(conversationId: string): Promise<number>;

View file

@ -10,6 +10,7 @@ import { randomBytes } from 'crypto';
import type { Database, Statement } from '@signalapp/better-sqlite3';
import SQL from '@signalapp/better-sqlite3';
import pProps from 'p-props';
import { v4 as generateUuid } from 'uuid';
import { z } from 'zod';
import type { Dictionary } from 'lodash';
@ -33,8 +34,9 @@ import { ReadStatus } from '../messages/MessageReadStatus';
import type { GroupV2MemberType } from '../model-types.d';
import type { ReactionType } from '../types/Reactions';
import { STORAGE_UI_KEYS } from '../types/StorageUIKeys';
import { UUID } from '../types/UUID';
import type { UUIDStringType } from '../types/UUID';
import type { StoryDistributionIdString } from '../types/StoryDistributionId';
import type { ServiceIdString, AciString } from '../types/ServiceId';
import { isServiceIdString } from '../types/ServiceId';
import type { StoredJob } from '../jobs/types';
import { assertDev, assertSync, strictAssert } from '../util/assert';
import { combineNames } from '../util/combineNames';
@ -193,7 +195,7 @@ const dataInterface: ServerInterface = {
getKyberPreKeyById,
bulkAddKyberPreKeys,
removeKyberPreKeyById,
removeKyberPreKeysByUuid,
removeKyberPreKeysByServiceId,
removeAllKyberPreKeys,
getAllKyberPreKeys,
@ -201,7 +203,7 @@ const dataInterface: ServerInterface = {
getPreKeyById,
bulkAddPreKeys,
removePreKeyById,
removePreKeysByUuid,
removePreKeysByServiceId,
removeAllPreKeys,
getAllPreKeys,
@ -209,7 +211,7 @@ const dataInterface: ServerInterface = {
getSignedPreKeyById,
bulkAddSignedPreKeys,
removeSignedPreKeyById,
removeSignedPreKeysByUuid,
removeSignedPreKeysByServiceId,
removeAllSignedPreKeys,
getAllSignedPreKeys,
@ -242,7 +244,7 @@ const dataInterface: ServerInterface = {
bulkAddSessions,
removeSessionById,
removeSessionsByConversation,
removeSessionsByUUID,
removeSessionsByServiceId,
removeAllSessions,
getAllSessions,
@ -260,7 +262,7 @@ const dataInterface: ServerInterface = {
getAllConversations,
getAllConversationIds,
getAllGroupsInvolvingUuid,
getAllGroupsInvolvingServiceId,
searchMessages,
@ -707,10 +709,12 @@ async function removeKyberPreKeyById(
): Promise<void> {
return removeById(getInstance(), KYBER_PRE_KEYS_TABLE, id);
}
async function removeKyberPreKeysByUuid(uuid: UUIDStringType): Promise<void> {
async function removeKyberPreKeysByServiceId(
serviceId: ServiceIdString
): Promise<void> {
const db = getInstance();
db.prepare<Query>('DELETE FROM kyberPreKeys WHERE ourUuid IS $uuid;').run({
uuid,
uuid: serviceId,
});
}
async function removeAllKyberPreKeys(): Promise<void> {
@ -737,10 +741,12 @@ async function removePreKeyById(
): Promise<void> {
return removeById(getInstance(), PRE_KEYS_TABLE, id);
}
async function removePreKeysByUuid(uuid: UUIDStringType): Promise<void> {
async function removePreKeysByServiceId(
serviceId: ServiceIdString
): Promise<void> {
const db = getInstance();
db.prepare<Query>('DELETE FROM preKeys WHERE ourUuid IS $uuid;').run({
uuid,
uuid: serviceId,
});
}
async function removeAllPreKeys(): Promise<void> {
@ -771,10 +777,12 @@ async function removeSignedPreKeyById(
): Promise<void> {
return removeById(getInstance(), SIGNED_PRE_KEYS_TABLE, id);
}
async function removeSignedPreKeysByUuid(uuid: UUIDStringType): Promise<void> {
async function removeSignedPreKeysByServiceId(
serviceId: ServiceIdString
): Promise<void> {
const db = getInstance();
db.prepare<Query>('DELETE FROM signedPreKeys WHERE ourUuid IS $uuid;').run({
uuid,
uuid: serviceId,
});
}
async function removeAllSignedPreKeys(): Promise<void> {
@ -941,14 +949,18 @@ async function insertSentProto(
`
);
const recipientUuids = Object.keys(recipients);
for (const recipientUuid of recipientUuids) {
const deviceIds = recipients[recipientUuid];
const recipientServiceIds = Object.keys(recipients);
for (const recipientServiceId of recipientServiceIds) {
strictAssert(
isServiceIdString(recipientServiceId),
'Recipient must be a service id'
);
const deviceIds = recipients[recipientServiceId];
for (const deviceId of deviceIds) {
recipientStatement.run({
id,
recipientUuid,
recipientUuid: recipientServiceId,
deviceId,
});
}
@ -1013,11 +1025,11 @@ async function deleteSentProtoByMessageId(messageId: string): Promise<void> {
async function insertProtoRecipients({
id,
recipientUuid,
recipientServiceId,
deviceIds,
}: {
id: number;
recipientUuid: string;
recipientServiceId: ServiceIdString;
deviceIds: Array<number>;
}): Promise<void> {
const db = getInstance();
@ -1041,7 +1053,7 @@ async function insertProtoRecipients({
for (const deviceId of deviceIds) {
statement.run({
id,
recipientUuid,
recipientUuid: recipientServiceId,
deviceId,
});
}
@ -1064,7 +1076,7 @@ async function deleteSentProtoRecipient(
const successfulPhoneNumberShares = new Array<string>();
for (const item of items) {
const { timestamp, recipientUuid, deviceId } = item;
const { timestamp, recipientServiceId, deviceId } = item;
// 1. Figure out what payload we're talking about.
const rows = prepare(
@ -1079,7 +1091,7 @@ async function deleteSentProtoRecipient(
sendLogRecipients.recipientUuid = $recipientUuid AND
sendLogRecipients.deviceId = $deviceId;
`
).all({ timestamp, recipientUuid, deviceId });
).all({ timestamp, recipientUuid: recipientServiceId, deviceId });
if (!rows.length) {
continue;
}
@ -1102,7 +1114,7 @@ async function deleteSentProtoRecipient(
recipientUuid = $recipientUuid AND
deviceId = $deviceId;
`
).run({ id, recipientUuid, deviceId });
).run({ id, recipientUuid: recipientServiceId, deviceId });
// 3. See how many more recipient devices there were for this payload.
const remainingDevices = prepare(
@ -1112,17 +1124,17 @@ async function deleteSentProtoRecipient(
WHERE payloadId = $id AND recipientUuid = $recipientUuid;
`,
{ pluck: true }
).get({ id, recipientUuid });
).get({ id, recipientUuid: recipientServiceId });
// 4. If there are no remaining devices for this recipient and we included
// the pni signature in the proto - return the recipient to the caller.
if (remainingDevices === 0 && hasPniSignatureMessage) {
logger.info(
'deleteSentProtoRecipient: ' +
`Successfully shared phone number with ${recipientUuid} ` +
`Successfully shared phone number with ${recipientServiceId} ` +
`through message ${timestamp}`
);
successfulPhoneNumberShares.push(recipientUuid);
successfulPhoneNumberShares.push(recipientServiceId);
}
strictAssert(
@ -1163,11 +1175,11 @@ async function deleteSentProtoRecipient(
async function getSentProtoByRecipient({
now,
recipientUuid,
recipientServiceId,
timestamp,
}: {
now: number;
recipientUuid: string;
recipientServiceId: ServiceIdString;
timestamp: number;
}): Promise<SentProtoWithMessageIdsType | undefined> {
const db = getInstance();
@ -1193,7 +1205,7 @@ async function getSentProtoByRecipient({
`
).get({
timestamp,
recipientUuid,
recipientUuid: recipientServiceId,
});
if (!row) {
@ -1348,7 +1360,9 @@ async function removeSessionsByConversation(
conversationId,
});
}
async function removeSessionsByUUID(uuid: UUIDStringType): Promise<void> {
async function removeSessionsByServiceId(
serviceId: ServiceIdString
): Promise<void> {
const db = getInstance();
db.prepare<Query>(
`
@ -1356,7 +1370,7 @@ async function removeSessionsByUUID(uuid: UUIDStringType): Promise<void> {
WHERE uuid = $uuid;
`
).run({
uuid,
uuid: serviceId,
});
}
async function removeAllSessions(): Promise<void> {
@ -1641,8 +1655,8 @@ async function getAllConversationIds(): Promise<Array<string>> {
return rows.map(row => row.id);
}
async function getAllGroupsInvolvingUuid(
uuid: UUIDStringType
async function getAllGroupsInvolvingServiceId(
serviceId: ServiceIdString
): Promise<Array<ConversationType>> {
const db = getInstance();
const rows: ConversationRows = db
@ -1656,7 +1670,7 @@ async function getAllGroupsInvolvingUuid(
`
)
.all({
uuid: `%${uuid}%`,
uuid: `%${serviceId}%`,
});
return rows.map(row => rowToConversation(row));
@ -1889,7 +1903,7 @@ function saveMessageSync(
db?: Database;
forceSave?: boolean;
jobToInsert?: StoredJob;
ourUuid: UUIDStringType;
ourAci: AciString;
}
): string {
const {
@ -1897,7 +1911,7 @@ function saveMessageSync(
db = getInstance(),
forceSave,
jobToInsert,
ourUuid,
ourAci,
} = options;
if (!alreadyInTransaction) {
@ -1976,7 +1990,7 @@ function saveMessageSync(
hasAttachments: hasAttachments ? 1 : 0,
hasFileAttachments: hasFileAttachments ? 1 : 0,
hasVisualMediaAttachments: hasVisualMediaAttachments ? 1 : 0,
isChangeCreatedByUs: groupV2Change?.from === ourUuid ? 1 : 0,
isChangeCreatedByUs: groupV2Change?.from === ourAci ? 1 : 0,
isErased: isErased ? 1 : 0,
isViewOnce: isViewOnce ? 1 : 0,
mentionsMe: mentionsMe ? 1 : 0,
@ -2038,7 +2052,7 @@ function saveMessageSync(
const toCreate = {
...data,
id: id || UUID.generate().toString(),
id: id || generateUuid(),
};
prepare(
@ -2119,7 +2133,7 @@ async function saveMessage(
jobToInsert?: StoredJob;
forceSave?: boolean;
alreadyInTransaction?: boolean;
ourUuid: UUIDStringType;
ourAci: AciString;
}
): Promise<string> {
return saveMessageSync(data, options);
@ -2127,7 +2141,7 @@ async function saveMessage(
async function saveMessages(
arrayOfMessages: ReadonlyArray<MessageType>,
options: { forceSave?: boolean; ourUuid: UUIDStringType }
options: { forceSave?: boolean; ourAci: AciString }
): Promise<void> {
const db = getInstance();
@ -2235,7 +2249,7 @@ async function getMessageBySender({
sent_at,
}: {
source?: string;
sourceUuid?: UUIDStringType;
sourceUuid?: ServiceIdString;
sourceDevice?: number;
sent_at: number;
}): Promise<MessageType | undefined> {
@ -2432,7 +2446,7 @@ async function getUnreadReactionsAndMarkRead({
}
async function markReactionAsRead(
targetAuthorUuid: string,
targetAuthorServiceId: ServiceIdString,
targetTimestamp: number
): Promise<ReactionType | undefined> {
const db = getInstance();
@ -2451,7 +2465,7 @@ async function markReactionAsRead(
`
)
.get({
targetAuthorUuid,
targetAuthorUuid: targetAuthorServiceId,
targetTimestamp,
});
@ -2463,7 +2477,7 @@ async function markReactionAsRead(
targetTimestamp = $targetTimestamp;
`
).run({
targetAuthorUuid,
targetAuthorUuid: targetAuthorServiceId,
targetTimestamp,
});
@ -2518,12 +2532,12 @@ async function addReaction({
async function removeReactionFromConversation({
emoji,
fromId,
targetAuthorUuid,
targetAuthorServiceId,
targetTimestamp,
}: {
emoji: string;
fromId: string;
targetAuthorUuid: string;
targetAuthorServiceId: ServiceIdString;
targetTimestamp: number;
}): Promise<void> {
const db = getInstance();
@ -2538,7 +2552,7 @@ async function removeReactionFromConversation({
.run({
emoji,
fromId,
targetAuthorUuid,
targetAuthorUuid: targetAuthorServiceId,
targetTimestamp,
});
}
@ -2711,7 +2725,7 @@ async function getAllStories({
sourceUuid,
}: {
conversationId?: string;
sourceUuid?: UUIDStringType;
sourceUuid?: ServiceIdString;
}): Promise<GetAllStoriesResultType> {
const db = getInstance();
const rows: ReadonlyArray<{
@ -2912,11 +2926,9 @@ async function getNearbyMessageFromDeletedSet({
function getLastConversationActivity({
conversationId,
includeStoryReplies,
ourUuid,
}: {
conversationId: string;
includeStoryReplies: boolean;
ourUuid: UUIDStringType;
}): MessageType | undefined {
const db = getInstance();
const row = prepare(
@ -2935,7 +2947,6 @@ function getLastConversationActivity({
`
).get({
conversationId,
ourUuid,
});
if (!row) {
@ -2988,11 +2999,9 @@ function getLastConversationPreview({
async function getConversationMessageStats({
conversationId,
includeStoryReplies,
ourUuid,
}: {
conversationId: string;
includeStoryReplies: boolean;
ourUuid: UUIDStringType;
}): Promise<ConversationMessageStatsType> {
const db = getInstance();
@ -3001,7 +3010,6 @@ async function getConversationMessageStats({
activity: getLastConversationActivity({
conversationId,
includeStoryReplies,
ourUuid,
}),
preview: getLastConversationPreview({
conversationId,
@ -3318,7 +3326,7 @@ async function getCallHistoryMessageByCallId(options: {
async function getCallHistory(
callId: string,
peerId: string
peerId: ServiceIdString | string
): Promise<CallHistoryDetails | undefined> {
const db = getInstance();
@ -5292,7 +5300,7 @@ function modifyStoryDistributionMembersSync(
{
toAdd,
toRemove,
}: { toAdd: Array<UUIDStringType>; toRemove: Array<UUIDStringType> }
}: { toAdd: Array<ServiceIdString>; toRemove: Array<ServiceIdString> }
) {
const memberInsertStatement = prepare(
db,
@ -5314,7 +5322,7 @@ function modifyStoryDistributionMembersSync(
});
}
batchMultiVarQuery(db, toRemove, (uuids: ReadonlyArray<UUIDStringType>) => {
batchMultiVarQuery(db, toRemove, (uuids: ReadonlyArray<ServiceIdString>) => {
db.prepare<ArrayQuery>(
`
DELETE FROM storyDistributionMembers
@ -5328,7 +5336,7 @@ async function modifyStoryDistributionWithMembers(
{
toAdd,
toRemove,
}: { toAdd: Array<UUIDStringType>; toRemove: Array<UUIDStringType> }
}: { toAdd: Array<ServiceIdString>; toRemove: Array<ServiceIdString> }
): Promise<void> {
const payload = freezeStoryDistribution(distribution);
const db = getInstance();
@ -5354,7 +5362,7 @@ async function modifyStoryDistributionMembers(
{
toAdd,
toRemove,
}: { toAdd: Array<UUIDStringType>; toRemove: Array<UUIDStringType> }
}: { toAdd: Array<ServiceIdString>; toRemove: Array<ServiceIdString> }
): Promise<void> {
const db = getInstance();
@ -5362,7 +5370,9 @@ async function modifyStoryDistributionMembers(
modifyStoryDistributionMembersSync(db, listId, { toAdd, toRemove });
})();
}
async function deleteStoryDistribution(id: UUIDStringType): Promise<void> {
async function deleteStoryDistribution(
id: StoryDistributionIdString
): Promise<void> {
const db = getInstance();
db.prepare<Query>('DELETE FROM storyDistributions WHERE id = $id;').run({
id,
@ -5402,8 +5412,8 @@ async function getLastStoryReadsForAuthor({
conversationId,
limit: initialLimit,
}: {
authorId: UUIDStringType;
conversationId?: UUIDStringType;
authorId: ServiceIdString;
conversationId?: string;
limit?: number;
}): Promise<Array<StoryReadType>> {
const limit = initialLimit || 5;
@ -6228,7 +6238,7 @@ async function removeAllProfileKeyCredentials(): Promise<void> {
async function saveEditedMessage(
mainMessage: MessageType,
ourUuid: UUIDStringType,
ourAci: AciString,
{ conversationId, messageId, readStatus, sentAt }: EditedMessageType
): Promise<void> {
const db = getInstance();
@ -6236,7 +6246,7 @@ async function saveEditedMessage(
db.transaction(() => {
assertSync(
saveMessageSync(mainMessage, {
ourUuid,
ourAci,
alreadyInTransaction: true,
})
);

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,