Normalize UUID in ConversationModel.initialize

This commit is contained in:
Fedor Indutny 2022-02-02 13:41:29 -08:00 committed by GitHub
parent f03cf1ba0e
commit fdbb2bfb36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 6 deletions

View file

@ -17,6 +17,7 @@ import type {
WhatIsThis,
} from '../model-types.d';
import { getInitials } from '../util/getInitials';
import { normalizeUuid } from '../util/normalizeUuid';
import type { AttachmentType } from '../types/Attachment';
import { isGIF } from '../types/Attachment';
import type { CallHistoryDetailsType } from '../types/Calling';
@ -259,6 +260,17 @@ export class ConversationModel extends window.Backbone
override initialize(
attributes: Partial<ConversationAttributesType> = {}
): void {
const uuid = this.get('uuid');
const normalizedUuid =
uuid && normalizeUuid(uuid, 'ConversationModel.initialize');
if (uuid && normalizedUuid !== uuid) {
log.warn(
'ConversationModel.initialize: normalizing uuid from ' +
`${uuid} to ${normalizedUuid}`
);
this.set('uuid', normalizedUuid);
}
if (isValidE164(attributes.id, false)) {
this.set({ id: UUID.generate().toString(), e164: attributes.id });
}