From 89516655549f579c60d75d3d53c0f317a33bcb33 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Tue, 13 Jul 2021 17:46:02 -0700 Subject: [PATCH] Clean up conversations with UUID as E164 --- ts/ConversationController.ts | 13 +++++++++++++ ts/state/selectors/conversations.ts | 8 ++++---- ts/test-both/state/selectors/conversations_test.ts | 10 +++++----- ts/util/findAndFormatContact.ts | 3 +-- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/ts/ConversationController.ts b/ts/ConversationController.ts index 9f3aeee13371..ab6b6e00b1f9 100644 --- a/ts/ConversationController.ts +++ b/ts/ConversationController.ts @@ -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'; @@ -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', diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index 16871388a380..649193a9f1e1 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -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); diff --git a/ts/test-both/state/selectors/conversations_test.ts b/ts/test-both/state/selectors/conversations_test.ts index b5b8d120316f..3658307243d0 100644 --- a/ts/test-both/state/selectors/conversations_test.ts +++ b/ts/test-both/state/selectors/conversations_test.ts @@ -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); @@ -116,10 +116,10 @@ describe('both/state/selectors/conversations', () => { [id]: wrongConversation, }, conversationsByE164: { - [id]: conversation, + [id]: wrongConversation, }, conversationsByUuid: { - [id]: wrongConversation, + [id]: conversation, }, conversationsByGroupId: { [id]: wrongConversation, @@ -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); @@ -146,7 +146,7 @@ describe('both/state/selectors/conversations', () => { conversationLookup: { [id]: wrongConversation, }, - conversationsByUuid: { + conversationsByE164: { [id]: conversation, }, conversationsByGroupId: { diff --git a/ts/util/findAndFormatContact.ts b/ts/util/findAndFormatContact.ts index f7a8643c8bd0..0b20fa9064ae 100644 --- a/ts/util/findAndFormatContact.ts +++ b/ts/util/findAndFormatContact.ts @@ -3,7 +3,6 @@ import { ConversationType } from '../state/ducks/conversations'; import { format, isValidNumber } from '../types/PhoneNumber'; -import { normalizeUuid } from './normalizeUuid'; type FormattedContact = Partial & Pick< @@ -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();