Clean up conversations with UUID as E164
This commit is contained in:
parent
a22dcc986f
commit
8951665554
4 changed files with 23 additions and 11 deletions
|
@ -13,6 +13,7 @@ import { SendOptionsType, CallbackResultType } from './textsecure/SendMessage';
|
||||||
import { ConversationModel } from './models/conversations';
|
import { ConversationModel } from './models/conversations';
|
||||||
import { maybeDeriveGroupV2Id } from './groups';
|
import { maybeDeriveGroupV2Id } from './groups';
|
||||||
import { assert } from './util/assert';
|
import { assert } from './util/assert';
|
||||||
|
import { isValidGuid } from './util/isValidGuid';
|
||||||
import { map, reduce } from './util/iterables';
|
import { map, reduce } from './util/iterables';
|
||||||
import { isGroupV1, isGroupV2 } from './util/whatTypeOfConversation';
|
import { isGroupV1, isGroupV2 } from './util/whatTypeOfConversation';
|
||||||
import { deprecated } from './util/deprecated';
|
import { deprecated } from './util/deprecated';
|
||||||
|
@ -843,6 +844,18 @@ export class ConversationController {
|
||||||
});
|
});
|
||||||
updateConversation(conversation.attributes);
|
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) {
|
} catch (error) {
|
||||||
window.log.error(
|
window.log.error(
|
||||||
'ConversationController.load/map: Failed to prepare a conversation',
|
'ConversationController.load/map: Failed to prepare a conversation',
|
||||||
|
|
|
@ -619,14 +619,14 @@ export const getConversationSelector = createSelector(
|
||||||
return selector(undefined);
|
return selector(undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
const onE164 = getOwn(byE164, id);
|
|
||||||
if (onE164) {
|
|
||||||
return selector(onE164);
|
|
||||||
}
|
|
||||||
const onUuid = getOwn(byUuid, id.toLowerCase ? id.toLowerCase() : id);
|
const onUuid = getOwn(byUuid, id.toLowerCase ? id.toLowerCase() : id);
|
||||||
if (onUuid) {
|
if (onUuid) {
|
||||||
return selector(onUuid);
|
return selector(onUuid);
|
||||||
}
|
}
|
||||||
|
const onE164 = getOwn(byE164, id);
|
||||||
|
if (onE164) {
|
||||||
|
return selector(onE164);
|
||||||
|
}
|
||||||
const onGroupId = getOwn(byGroupId, id);
|
const onGroupId = getOwn(byGroupId, id);
|
||||||
if (onGroupId) {
|
if (onGroupId) {
|
||||||
return selector(onGroupId);
|
return selector(onGroupId);
|
||||||
|
|
|
@ -102,7 +102,7 @@ describe('both/state/selectors/conversations', () => {
|
||||||
assert.deepEqual(actual, getPlaceholderContact());
|
assert.deepEqual(actual, getPlaceholderContact());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns conversation by e164 first', () => {
|
it('returns conversation by uuid first', () => {
|
||||||
const id = 'id';
|
const id = 'id';
|
||||||
|
|
||||||
const conversation = makeConversation(id);
|
const conversation = makeConversation(id);
|
||||||
|
@ -116,10 +116,10 @@ describe('both/state/selectors/conversations', () => {
|
||||||
[id]: wrongConversation,
|
[id]: wrongConversation,
|
||||||
},
|
},
|
||||||
conversationsByE164: {
|
conversationsByE164: {
|
||||||
[id]: conversation,
|
[id]: wrongConversation,
|
||||||
},
|
},
|
||||||
conversationsByUuid: {
|
conversationsByUuid: {
|
||||||
[id]: wrongConversation,
|
[id]: conversation,
|
||||||
},
|
},
|
||||||
conversationsByGroupId: {
|
conversationsByGroupId: {
|
||||||
[id]: wrongConversation,
|
[id]: wrongConversation,
|
||||||
|
@ -133,7 +133,7 @@ describe('both/state/selectors/conversations', () => {
|
||||||
|
|
||||||
assert.strictEqual(actual, conversation);
|
assert.strictEqual(actual, conversation);
|
||||||
});
|
});
|
||||||
it('returns conversation by uuid', () => {
|
it('returns conversation by e164', () => {
|
||||||
const id = 'id';
|
const id = 'id';
|
||||||
|
|
||||||
const conversation = makeConversation(id);
|
const conversation = makeConversation(id);
|
||||||
|
@ -146,7 +146,7 @@ describe('both/state/selectors/conversations', () => {
|
||||||
conversationLookup: {
|
conversationLookup: {
|
||||||
[id]: wrongConversation,
|
[id]: wrongConversation,
|
||||||
},
|
},
|
||||||
conversationsByUuid: {
|
conversationsByE164: {
|
||||||
[id]: conversation,
|
[id]: conversation,
|
||||||
},
|
},
|
||||||
conversationsByGroupId: {
|
conversationsByGroupId: {
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
import { ConversationType } from '../state/ducks/conversations';
|
import { ConversationType } from '../state/ducks/conversations';
|
||||||
import { format, isValidNumber } from '../types/PhoneNumber';
|
import { format, isValidNumber } from '../types/PhoneNumber';
|
||||||
import { normalizeUuid } from './normalizeUuid';
|
|
||||||
|
|
||||||
type FormattedContact = Partial<ConversationType> &
|
type FormattedContact = Partial<ConversationType> &
|
||||||
Pick<
|
Pick<
|
||||||
|
@ -32,7 +31,7 @@ export function findAndFormatContact(identifier?: string): FormattedContact {
|
||||||
}
|
}
|
||||||
|
|
||||||
const contactModel = window.ConversationController.get(
|
const contactModel = window.ConversationController.get(
|
||||||
normalizeUuid(identifier, 'findAndFormatContact')
|
identifier.toLowerCase()
|
||||||
);
|
);
|
||||||
if (contactModel) {
|
if (contactModel) {
|
||||||
return contactModel.format();
|
return contactModel.format();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue