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

@ -3,7 +3,7 @@
import * as sinon from 'sinon';
import { Job } from '../../../jobs/Job';
import { UUID } from '../../../types/UUID';
import { generateAci } from '../../../types/ServiceId';
import { addReportSpamJob } from '../../../jobs/helpers/addReportSpamJob';
@ -14,7 +14,7 @@ describe('addReportSpamJob', () => {
const conversation = {
id: 'convo',
type: 'private' as const,
uuid: UUID.generate().toString(),
uuid: generateAci(),
};
beforeEach(() => {

View file

@ -9,9 +9,15 @@ import {
getDeltaToRestartMention,
} from '../../quill/util';
import { BodyRange } from '../../types/BodyRange';
import { generateAci } from '../../types/ServiceId';
const SERVICE_ID_1 = generateAci();
const SERVICE_ID_2 = generateAci();
const SERVICE_ID_3 = generateAci();
const SERVICE_ID_4 = generateAci();
describe('getDeltaToRemoveStaleMentions', () => {
const memberUuids = ['abcdef', 'ghijkl'];
const memberUuids = [SERVICE_ID_1, SERVICE_ID_2];
describe('given text', () => {
it('retains the text', () => {
@ -32,10 +38,10 @@ describe('getDeltaToRemoveStaleMentions', () => {
const originalOps = [
{
insert: {
mention: { uuid: '12345', title: 'Klaus' },
mention: { uuid: SERVICE_ID_3, title: 'Klaus' },
},
},
{ insert: { mention: { uuid: 'abcdef', title: 'Werner' } } },
{ insert: { mention: { uuid: SERVICE_ID_1, title: 'Werner' } } },
];
const { ops } = getDeltaToRemoveStaleMentions(originalOps, memberUuids);
@ -279,7 +285,7 @@ describe('getTextAndRangesFromOps', () => {
{
insert: {
mention: {
uuid: 'abcdef',
uuid: SERVICE_ID_1,
title: '@fred',
},
},
@ -290,7 +296,7 @@ describe('getTextAndRangesFromOps', () => {
assert.deepEqual(bodyRanges, [
{
length: 1,
mentionUuid: 'abcdef',
mentionUuid: SERVICE_ID_1,
replacementText: '@fred',
start: 15,
},
@ -304,7 +310,7 @@ describe('getTextAndRangesFromOps', () => {
{
insert: {
mention: {
uuid: 'abcdef',
uuid: SERVICE_ID_1,
title: '@fred',
},
},
@ -315,7 +321,7 @@ describe('getTextAndRangesFromOps', () => {
assert.deepEqual(bodyRanges, [
{
length: 1,
mentionUuid: 'abcdef',
mentionUuid: SERVICE_ID_1,
replacementText: '@fred',
start: 0,
},
@ -328,7 +334,7 @@ describe('getTextAndRangesFromOps', () => {
{
insert: {
mention: {
uuid: 'abcdef',
uuid: SERVICE_ID_1,
title: '@fred',
},
},
@ -340,7 +346,7 @@ describe('getTextAndRangesFromOps', () => {
assert.deepEqual(bodyRanges, [
{
length: 1,
mentionUuid: 'abcdef',
mentionUuid: SERVICE_ID_1,
replacementText: '@fred',
start: 6,
},
@ -360,7 +366,7 @@ describe('getTextAndRangesFromOps', () => {
{
insert: {
mention: {
uuid: 'a',
uuid: SERVICE_ID_4,
title: '@alice',
},
},
@ -419,7 +425,7 @@ describe('getTextAndRangesFromOps', () => {
{
start: 5,
length: 1,
mentionUuid: 'a',
mentionUuid: SERVICE_ID_4,
replacementText: '@alice',
},
{
@ -503,7 +509,7 @@ describe('getTextAndRangesFromOps', () => {
{
insert: {
mention: {
uuid: 'a',
uuid: SERVICE_ID_4,
title: '@alice',
},
},
@ -518,7 +524,7 @@ describe('getTextAndRangesFromOps', () => {
{
start: 0,
length: 1,
mentionUuid: 'a',
mentionUuid: SERVICE_ID_4,
replacementText: '@alice',
},
{
@ -543,7 +549,7 @@ describe('getDeltaToRestartMention', () => {
{
insert: {
mention: {
uuid: 'ghijkl',
uuid: SERVICE_ID_2,
title: '@sam',
},
},
@ -554,7 +560,7 @@ describe('getDeltaToRestartMention', () => {
{
insert: {
mention: {
uuid: 'abcdef',
uuid: SERVICE_ID_1,
title: '@fred',
},
},

View file

@ -18,6 +18,8 @@ import { SeenStatus } from '../MessageSeenStatus';
import { objectToJSON, sql, sqlJoin } from '../sql/util';
import type { MessageType } from '../sql/Interface';
import { BodyRange } from '../types/BodyRange';
import type { AciString } from '../types/ServiceId';
import { generateAci } from '../types/ServiceId';
import { CallMode } from '../types/Calling';
import { callHistoryDetailsSchema } from '../types/CallDisposition';
import type { MessageAttributesType } from '../model-types';
@ -98,7 +100,7 @@ describe('SQL migrations test', () => {
});
describe('updateToSchemaVersion41', () => {
const THEIR_UUID = generateGuid();
const THEIR_UUID = generateAci();
const THEIR_CONVO = generateGuid();
const ANOTHER_CONVO = generateGuid();
const THIRD_CONVO = generateGuid();
@ -635,9 +637,9 @@ describe('SQL migrations test', () => {
it('remaps conversation ids to UUIDs in groups and messages', () => {
updateToVersion(42);
const UUID_A = generateGuid();
const UUID_B = generateGuid();
const UUID_C = generateGuid();
const UUID_A = generateAci();
const UUID_B = generateAci();
const UUID_C = generateAci();
const rawConvoA = { id: 'a', groupId: 'gv2a', uuid: UUID_A };
const rawConvoB = { id: 'b', groupId: 'gv2b', uuid: UUID_B };
@ -874,10 +876,10 @@ describe('SQL migrations test', () => {
it('creates new storyDistributions/Members with cascade delete', () => {
const LIST_ID_1 = generateGuid();
const LIST_ID_2 = generateGuid();
const UUID_1 = generateGuid();
const UUID_2 = generateGuid();
const UUID_3 = generateGuid();
const UUID_4 = generateGuid();
const UUID_1 = generateAci();
const UUID_2 = generateAci();
const UUID_3 = generateAci();
const UUID_4 = generateAci();
updateToVersion(45);
@ -925,7 +927,7 @@ describe('SQL migrations test', () => {
describe('updateToSchemaVersion47', () => {
it('creates and pre-populates new isChangeCreatedByUs field', () => {
const OTHER_UUID = generateGuid();
const OTHER_UUID = generateAci();
const MESSAGE_ID_1 = generateGuid();
const MESSAGE_ID_2 = generateGuid();
const CONVERSATION_ID = generateGuid();
@ -1154,9 +1156,9 @@ describe('SQL migrations test', () => {
const MESSAGE_ID_4 = generateGuid();
const MESSAGE_ID_5 = generateGuid();
const CONVERSATION_ID = generateGuid();
const FIRST_UUID = generateGuid();
const SECOND_UUID = generateGuid();
const THIRD_UUID = generateGuid();
const FIRST_UUID = generateAci();
const SECOND_UUID = generateAci();
const THIRD_UUID = generateAci();
updateToVersion(47);
@ -1679,9 +1681,9 @@ describe('SQL migrations test', () => {
it('remaps bannedMembersV2 to array of objects', () => {
updateToVersion(52);
const UUID_A = generateGuid();
const UUID_B = generateGuid();
const UUID_C = generateGuid();
const UUID_A = generateAci();
const UUID_B = generateAci();
const UUID_C = generateAci();
const noMembers = { id: 'a', groupId: 'gv2a' };
const emptyMembers = {
@ -3200,7 +3202,7 @@ describe('SQL migrations test', () => {
boldRanges,
}: {
id?: string;
mentions?: Array<string>;
mentions?: Array<AciString>;
boldRanges?: Array<Array<number>>;
}) {
const json: Partial<MessageType> = {
@ -3230,7 +3232,7 @@ describe('SQL migrations test', () => {
function addMessages(
messages: Array<{
mentions?: Array<string>;
mentions?: Array<AciString>;
boldRanges?: Array<Array<number>>;
}>
) {
@ -3264,7 +3266,7 @@ describe('SQL migrations test', () => {
it('Creates and populates the mentions table with existing mentions', () => {
updateToVersion(schemaVersion - 1);
const userIds = new Array(5).fill(undefined).map(() => generateGuid());
const userIds = new Array(5).fill(undefined).map(() => generateAci());
const { formattedMessages } = addMessages([
{ mentions: [userIds[0]] },
{ mentions: [userIds[1]], boldRanges: [[1, 1]] },
@ -3316,7 +3318,7 @@ describe('SQL migrations test', () => {
0
);
const userIds = new Array(5).fill(undefined).map(() => generateGuid());
const userIds = new Array(5).fill(undefined).map(() => generateAci());
const { formattedMessages } = addMessages([
{ mentions: [userIds[0]] },
{ mentions: [userIds[1]], boldRanges: [[1, 1]] },
@ -3364,7 +3366,7 @@ describe('SQL migrations test', () => {
0
);
const userIds = new Array(5).fill(undefined).map(() => generateGuid());
const userIds = new Array(5).fill(undefined).map(() => generateAci());
const { formattedMessages } = addMessages([
{ mentions: [userIds[0]] },
{ mentions: [userIds[1], userIds[2]], boldRanges: [[1, 1]] },
@ -3394,7 +3396,7 @@ describe('SQL migrations test', () => {
0
);
const userIds = new Array(5).fill(undefined).map(() => generateGuid());
const userIds = new Array(5).fill(undefined).map(() => generateAci());
const { formattedMessages } = addMessages([{ mentions: [userIds[0]] }]);
assert.equal(getMentions().length, 1);

View file

@ -15,7 +15,7 @@ import {
parseAndWriteAvatar,
} from '../../types/EmbeddedContact';
import { fakeAttachment } from '../../test-both/helpers/fakeAttachment';
import { UUID } from '../../types/UUID';
import { generateAci } from '../../types/ServiceId';
describe('Contact', () => {
const NUMBER = '+12025550099';
@ -197,7 +197,7 @@ describe('Contact', () => {
});
it('calculates absolute path', () => {
const fullUuid = UUID.generate().toString();
const fullUuid = generateAci();
const contact = {
name: {