Skip to content

Commit

Permalink
Clean up conversations with UUID as E164
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny-signal committed Jul 14, 2021
1 parent a22dcc9 commit 8951665
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
13 changes: 13 additions & 0 deletions ts/ConversationController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { SendOptionsType, CallbackResultType } from './textsecure/SendMessage';
import { ConversationModel } from './models/conversations';
import { maybeDeriveGroupV2Id } from './groups';
import { assert } from './util/assert';
import { isValidGuid } from './util/isValidGuid';
import { map, reduce } from './util/iterables';
import { isGroupV1, isGroupV2 } from './util/whatTypeOfConversation';
import { deprecated } from './util/deprecated';
Expand Down Expand Up @@ -843,6 +844,18 @@ export class ConversationController {
});
updateConversation(conversation.attributes);
}

// Clean up the conversations that have UUID as their e164.
const e164 = conversation.get('e164');
const uuid = conversation.get('uuid');
if (isValidGuid(e164) && uuid) {
conversation.set({ e164: undefined });
updateConversation(conversation.attributes);

window.log.info(
`Cleaning up conversation(${uuid}) with invalid e164`
);
}
} catch (error) {
window.log.error(
'ConversationController.load/map: Failed to prepare a conversation',
Expand Down
8 changes: 4 additions & 4 deletions ts/state/selectors/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,14 +619,14 @@ export const getConversationSelector = createSelector(
return selector(undefined);
}

const onE164 = getOwn(byE164, id);
if (onE164) {
return selector(onE164);
}
const onUuid = getOwn(byUuid, id.toLowerCase ? id.toLowerCase() : id);
if (onUuid) {
return selector(onUuid);
}
const onE164 = getOwn(byE164, id);
if (onE164) {
return selector(onE164);
}
const onGroupId = getOwn(byGroupId, id);
if (onGroupId) {
return selector(onGroupId);
Expand Down
10 changes: 5 additions & 5 deletions ts/test-both/state/selectors/conversations_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('both/state/selectors/conversations', () => {
assert.deepEqual(actual, getPlaceholderContact());
});

it('returns conversation by e164 first', () => {
it('returns conversation by uuid first', () => {
const id = 'id';

const conversation = makeConversation(id);
Expand All @@ -116,10 +116,10 @@ describe('both/state/selectors/conversations', () => {
[id]: wrongConversation,
},
conversationsByE164: {
[id]: conversation,
[id]: wrongConversation,
},
conversationsByUuid: {
[id]: wrongConversation,
[id]: conversation,
},
conversationsByGroupId: {
[id]: wrongConversation,
Expand All @@ -133,7 +133,7 @@ describe('both/state/selectors/conversations', () => {

assert.strictEqual(actual, conversation);
});
it('returns conversation by uuid', () => {
it('returns conversation by e164', () => {
const id = 'id';

const conversation = makeConversation(id);
Expand All @@ -146,7 +146,7 @@ describe('both/state/selectors/conversations', () => {
conversationLookup: {
[id]: wrongConversation,
},
conversationsByUuid: {
conversationsByE164: {
[id]: conversation,
},
conversationsByGroupId: {
Expand Down
3 changes: 1 addition & 2 deletions ts/util/findAndFormatContact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import { ConversationType } from '../state/ducks/conversations';
import { format, isValidNumber } from '../types/PhoneNumber';
import { normalizeUuid } from './normalizeUuid';

type FormattedContact = Partial<ConversationType> &
Pick<
Expand Down Expand Up @@ -32,7 +31,7 @@ export function findAndFormatContact(identifier?: string): FormattedContact {
}

const contactModel = window.ConversationController.get(
normalizeUuid(identifier, 'findAndFormatContact')
identifier.toLowerCase()
);
if (contactModel) {
return contactModel.format();
Expand Down

0 comments on commit 8951665

Please sign in to comment.