Use UUIDs in group database schema
This commit is contained in:
parent
74fde10ff5
commit
63fcdbe787
79 changed files with 4530 additions and 3664 deletions
|
@ -48,8 +48,13 @@ import { noopAction } from '../../../state/ducks/noop';
|
|||
import type { StateType } from '../../../state/reducer';
|
||||
import { reducer as rootReducer } from '../../../state/reducer';
|
||||
import { setupI18n } from '../../../util/setupI18n';
|
||||
import { UUID } from '../../../types/UUID';
|
||||
import type { UUIDStringType } from '../../../types/UUID';
|
||||
import enMessages from '../../../../_locales/en/messages.json';
|
||||
import { getDefaultConversation } from '../../helpers/getDefaultConversation';
|
||||
import {
|
||||
getDefaultConversation,
|
||||
getDefaultConversationWithUuid,
|
||||
} from '../../helpers/getDefaultConversation';
|
||||
import {
|
||||
defaultStartDirectConversationComposerState,
|
||||
defaultChooseGroupMembersComposerState,
|
||||
|
@ -69,6 +74,19 @@ describe('both/state/selectors/conversations', () => {
|
|||
});
|
||||
}
|
||||
|
||||
function makeConversationWithUuid(
|
||||
id: string
|
||||
): ConversationType & { uuid: UUIDStringType } {
|
||||
return getDefaultConversationWithUuid(
|
||||
{
|
||||
id,
|
||||
searchableTitle: `${id} title`,
|
||||
title: `${id} title`,
|
||||
},
|
||||
UUID.fromPrefix(id).toString()
|
||||
);
|
||||
}
|
||||
|
||||
const i18n = setupI18n('en', enMessages);
|
||||
|
||||
describe('#getConversationByIdSelector', () => {
|
||||
|
@ -374,15 +392,17 @@ describe('both/state/selectors/conversations', () => {
|
|||
});
|
||||
|
||||
it('returns "hydrated" invited contacts', () => {
|
||||
const abc = makeConversationWithUuid('abc');
|
||||
const def = makeConversationWithUuid('def');
|
||||
const state = {
|
||||
...getEmptyRootState(),
|
||||
conversations: {
|
||||
...getEmptyState(),
|
||||
conversationLookup: {
|
||||
abc: makeConversation('abc'),
|
||||
def: makeConversation('def'),
|
||||
conversationsByUuid: {
|
||||
[abc.uuid]: abc,
|
||||
[def.uuid]: def,
|
||||
},
|
||||
invitedConversationIdsForNewlyCreatedGroup: ['def', 'abc'],
|
||||
invitedUuidsForNewlyCreatedGroup: [def.uuid, abc.uuid],
|
||||
},
|
||||
};
|
||||
const result = getInvitedContactsForNewlyCreatedGroup(state);
|
||||
|
@ -1826,23 +1846,17 @@ describe('both/state/selectors/conversations', () => {
|
|||
});
|
||||
|
||||
describe('#getContactNameColorSelector', () => {
|
||||
function makeConversationWithUuid(id: string): ConversationType {
|
||||
const convo = makeConversation(id);
|
||||
convo.uuid = id;
|
||||
return convo;
|
||||
}
|
||||
|
||||
it('returns the right color order sorted by UUID ASC', () => {
|
||||
const group = makeConversation('group');
|
||||
group.type = 'group';
|
||||
group.sortedGroupMembers = [
|
||||
makeConversationWithUuid('zyx'),
|
||||
makeConversationWithUuid('vut'),
|
||||
makeConversationWithUuid('srq'),
|
||||
makeConversationWithUuid('pon'),
|
||||
makeConversationWithUuid('mlk'),
|
||||
makeConversationWithUuid('jih'),
|
||||
makeConversationWithUuid('gfe'),
|
||||
makeConversationWithUuid('fff'),
|
||||
makeConversationWithUuid('f00'),
|
||||
makeConversationWithUuid('e00'),
|
||||
makeConversationWithUuid('d00'),
|
||||
makeConversationWithUuid('c00'),
|
||||
makeConversationWithUuid('b00'),
|
||||
makeConversationWithUuid('a00'),
|
||||
];
|
||||
const state = {
|
||||
...getEmptyRootState(),
|
||||
|
@ -1856,13 +1870,13 @@ describe('both/state/selectors/conversations', () => {
|
|||
|
||||
const contactNameColorSelector = getContactNameColorSelector(state);
|
||||
|
||||
assert.equal(contactNameColorSelector('group', 'gfe'), '200');
|
||||
assert.equal(contactNameColorSelector('group', 'jih'), '120');
|
||||
assert.equal(contactNameColorSelector('group', 'mlk'), '300');
|
||||
assert.equal(contactNameColorSelector('group', 'pon'), '010');
|
||||
assert.equal(contactNameColorSelector('group', 'srq'), '210');
|
||||
assert.equal(contactNameColorSelector('group', 'vut'), '330');
|
||||
assert.equal(contactNameColorSelector('group', 'zyx'), '230');
|
||||
assert.equal(contactNameColorSelector('group', 'a00'), '200');
|
||||
assert.equal(contactNameColorSelector('group', 'b00'), '120');
|
||||
assert.equal(contactNameColorSelector('group', 'c00'), '300');
|
||||
assert.equal(contactNameColorSelector('group', 'd00'), '010');
|
||||
assert.equal(contactNameColorSelector('group', 'e00'), '210');
|
||||
assert.equal(contactNameColorSelector('group', 'f00'), '330');
|
||||
assert.equal(contactNameColorSelector('group', 'fff'), '230');
|
||||
});
|
||||
|
||||
it('returns the right colors for direct conversation', () => {
|
||||
|
|
|
@ -19,7 +19,11 @@ import {
|
|||
getSearchResults,
|
||||
} from '../../../state/selectors/search';
|
||||
import { makeLookup } from '../../../util/makeLookup';
|
||||
import { getDefaultConversation } from '../../helpers/getDefaultConversation';
|
||||
import { UUID } from '../../../types/UUID';
|
||||
import {
|
||||
getDefaultConversation,
|
||||
getDefaultConversationWithUuid,
|
||||
} from '../../helpers/getDefaultConversation';
|
||||
import { ReadStatus } from '../../../messages/MessageReadStatus';
|
||||
|
||||
import type { StateType } from '../../../state/reducer';
|
||||
|
@ -52,7 +56,7 @@ describe('both/state/selectors/search', () => {
|
|||
received_at: NOW,
|
||||
sent_at: NOW,
|
||||
source: 'source',
|
||||
sourceUuid: 'sourceUuid',
|
||||
sourceUuid: UUID.generate().toString(),
|
||||
timestamp: NOW,
|
||||
type: 'incoming' as const,
|
||||
readStatus: ReadStatus.Read,
|
||||
|
@ -125,10 +129,9 @@ describe('both/state/selectors/search', () => {
|
|||
|
||||
it('returns incoming message', () => {
|
||||
const searchId = 'search-id';
|
||||
const fromId = 'from-id';
|
||||
const toId = 'to-id';
|
||||
|
||||
const from = getDefaultConversation({ id: fromId });
|
||||
const from = getDefaultConversationWithUuid();
|
||||
const to = getDefaultConversation({ id: toId });
|
||||
|
||||
const state = {
|
||||
|
@ -136,9 +139,12 @@ describe('both/state/selectors/search', () => {
|
|||
conversations: {
|
||||
...getEmptyConversationState(),
|
||||
conversationLookup: {
|
||||
[fromId]: from,
|
||||
[from.id]: from,
|
||||
[toId]: to,
|
||||
},
|
||||
conversationsByUuid: {
|
||||
[from.uuid]: from,
|
||||
},
|
||||
},
|
||||
search: {
|
||||
...getEmptySearchState(),
|
||||
|
@ -146,7 +152,7 @@ describe('both/state/selectors/search', () => {
|
|||
[searchId]: {
|
||||
...getDefaultMessage(searchId),
|
||||
type: 'incoming' as const,
|
||||
sourceUuid: fromId,
|
||||
sourceUuid: from.uuid,
|
||||
conversationId: toId,
|
||||
snippet: 'snippet',
|
||||
body: 'snippet',
|
||||
|
@ -178,11 +184,10 @@ describe('both/state/selectors/search', () => {
|
|||
|
||||
it('returns the correct "from" and "to" when sent to me', () => {
|
||||
const searchId = 'search-id';
|
||||
const fromId = 'from-id';
|
||||
const toId = fromId;
|
||||
const myId = 'my-id';
|
||||
|
||||
const from = getDefaultConversation({ id: fromId });
|
||||
const from = getDefaultConversationWithUuid();
|
||||
const toId = from.uuid;
|
||||
const meAsRecipient = getDefaultConversation({ id: myId });
|
||||
|
||||
const state = {
|
||||
|
@ -190,9 +195,12 @@ describe('both/state/selectors/search', () => {
|
|||
conversations: {
|
||||
...getEmptyConversationState(),
|
||||
conversationLookup: {
|
||||
[fromId]: from,
|
||||
[from.id]: from,
|
||||
[myId]: meAsRecipient,
|
||||
},
|
||||
conversationsByUuid: {
|
||||
[from.uuid]: from,
|
||||
},
|
||||
},
|
||||
ourConversationId: myId,
|
||||
search: {
|
||||
|
@ -201,7 +209,7 @@ describe('both/state/selectors/search', () => {
|
|||
[searchId]: {
|
||||
...getDefaultMessage(searchId),
|
||||
type: 'incoming' as const,
|
||||
sourceUuid: fromId,
|
||||
sourceUuid: from.uuid,
|
||||
conversationId: toId,
|
||||
snippet: 'snippet',
|
||||
body: 'snippet',
|
||||
|
@ -223,24 +231,26 @@ describe('both/state/selectors/search', () => {
|
|||
|
||||
it('returns outgoing message and caches appropriately', () => {
|
||||
const searchId = 'search-id';
|
||||
const fromId = 'from-id';
|
||||
const toId = 'to-id';
|
||||
|
||||
const from = getDefaultConversation({ id: fromId });
|
||||
const from = getDefaultConversationWithUuid();
|
||||
const to = getDefaultConversation({ id: toId });
|
||||
|
||||
const state = {
|
||||
...getEmptyRootState(),
|
||||
user: {
|
||||
...getEmptyUserState(),
|
||||
ourConversationId: fromId,
|
||||
ourConversationId: from.id,
|
||||
},
|
||||
conversations: {
|
||||
...getEmptyConversationState(),
|
||||
conversationLookup: {
|
||||
[fromId]: from,
|
||||
[from.id]: from,
|
||||
[toId]: to,
|
||||
},
|
||||
conversationsByUuid: {
|
||||
[from.uuid]: from,
|
||||
},
|
||||
},
|
||||
search: {
|
||||
...getEmptySearchState(),
|
||||
|
@ -293,9 +303,9 @@ describe('both/state/selectors/search', () => {
|
|||
...state,
|
||||
conversations: {
|
||||
...state.conversations,
|
||||
conversationLookup: {
|
||||
...state.conversations.conversationLookup,
|
||||
[fromId]: {
|
||||
conversationsByUuid: {
|
||||
...state.conversations.conversationsByUuid,
|
||||
[from.uuid]: {
|
||||
...from,
|
||||
name: 'new-name',
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue