Import log instead of using it off of window
This commit is contained in:
parent
8eb0dd3116
commit
65ddf0a9e8
155 changed files with 3654 additions and 3433 deletions
|
@ -19,6 +19,7 @@ import { isGroupV1, isGroupV2 } from './util/whatTypeOfConversation';
|
|||
import { UUID } from './types/UUID';
|
||||
import { Address } from './types/Address';
|
||||
import { QualifiedAddress } from './types/QualifiedAddress';
|
||||
import * as log from './logging/log';
|
||||
|
||||
const MAX_MESSAGE_BODY_LENGTH = 64 * 1024;
|
||||
|
||||
|
@ -233,7 +234,7 @@ export class ConversationController {
|
|||
const create = async () => {
|
||||
if (!conversation.isValid()) {
|
||||
const validationError = conversation.validationError || {};
|
||||
window.log.error(
|
||||
log.error(
|
||||
'Contact is not valid. Not saving, but adding to collection:',
|
||||
conversation.idForLogging(),
|
||||
validationError.stack
|
||||
|
@ -248,7 +249,7 @@ export class ConversationController {
|
|||
}
|
||||
await saveConversation(conversation.attributes);
|
||||
} catch (error) {
|
||||
window.log.error(
|
||||
log.error(
|
||||
'Conversation save failed! ',
|
||||
identifier,
|
||||
type,
|
||||
|
@ -368,9 +369,7 @@ export class ConversationController {
|
|||
|
||||
// 1. Handle no match at all
|
||||
if (!convoE164 && !convoUuid) {
|
||||
window.log.info(
|
||||
'ensureContactIds: Creating new contact, no matches found'
|
||||
);
|
||||
log.info('ensureContactIds: Creating new contact, no matches found');
|
||||
const newConvo = this.getOrCreate(identifier, 'private');
|
||||
if (highTrust && e164) {
|
||||
newConvo.updateE164(e164);
|
||||
|
@ -388,7 +387,7 @@ export class ConversationController {
|
|||
}
|
||||
if (convoE164 && !convoUuid) {
|
||||
const haveUuid = Boolean(normalizedUuid);
|
||||
window.log.info(
|
||||
log.info(
|
||||
`ensureContactIds: e164-only match found (have UUID: ${haveUuid})`
|
||||
);
|
||||
// If we are only searching based on e164 anyway, then return the first result
|
||||
|
@ -399,23 +398,21 @@ export class ConversationController {
|
|||
// Fill in the UUID for an e164-only contact
|
||||
if (normalizedUuid && !convoE164.get('uuid')) {
|
||||
if (highTrust) {
|
||||
window.log.info('ensureContactIds: Adding UUID to e164-only match');
|
||||
log.info('ensureContactIds: Adding UUID to e164-only match');
|
||||
convoE164.updateUuid(normalizedUuid);
|
||||
updateConversation(convoE164.attributes);
|
||||
}
|
||||
return convoE164.get('id');
|
||||
}
|
||||
|
||||
window.log.info(
|
||||
log.info(
|
||||
'ensureContactIds: e164 already had UUID, creating a new contact'
|
||||
);
|
||||
// If existing e164 match already has UUID, create a new contact...
|
||||
const newConvo = this.getOrCreate(normalizedUuid, 'private');
|
||||
|
||||
if (highTrust) {
|
||||
window.log.info(
|
||||
'ensureContactIds: Moving e164 from old contact to new'
|
||||
);
|
||||
log.info('ensureContactIds: Moving e164 from old contact to new');
|
||||
|
||||
// Remove the e164 from the old contact...
|
||||
convoE164.set({ e164: undefined });
|
||||
|
@ -432,7 +429,7 @@ export class ConversationController {
|
|||
}
|
||||
if (!convoE164 && convoUuid) {
|
||||
if (e164 && highTrust) {
|
||||
window.log.info('ensureContactIds: Adding e164 to UUID-only match');
|
||||
log.info('ensureContactIds: Adding e164 to UUID-only match');
|
||||
convoUuid.updateE164(e164);
|
||||
updateConversation(convoUuid.attributes);
|
||||
}
|
||||
|
@ -454,7 +451,7 @@ export class ConversationController {
|
|||
if (highTrust) {
|
||||
// Conflict: If e164 match already has a UUID, we remove its e164.
|
||||
if (convoE164.get('uuid') && convoE164.get('uuid') !== normalizedUuid) {
|
||||
window.log.info(
|
||||
log.info(
|
||||
'ensureContactIds: e164 match had different UUID than incoming pair, removing its e164.'
|
||||
);
|
||||
|
||||
|
@ -469,7 +466,7 @@ export class ConversationController {
|
|||
return convoUuid.get('id');
|
||||
}
|
||||
|
||||
window.log.warn(
|
||||
log.warn(
|
||||
`ensureContactIds: Found a split contact - UUID ${normalizedUuid} and E164 ${e164}. Merging.`
|
||||
);
|
||||
|
||||
|
@ -488,9 +485,7 @@ export class ConversationController {
|
|||
})
|
||||
.catch(error => {
|
||||
const errorText = error && error.stack ? error.stack : error;
|
||||
window.log.warn(
|
||||
`ensureContactIds error combining contacts: ${errorText}`
|
||||
);
|
||||
log.warn(`ensureContactIds error combining contacts: ${errorText}`);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -498,7 +493,7 @@ export class ConversationController {
|
|||
}
|
||||
|
||||
async checkForConflicts(): Promise<void> {
|
||||
window.log.info('checkForConflicts: starting...');
|
||||
log.info('checkForConflicts: starting...');
|
||||
const byUuid = Object.create(null);
|
||||
const byE164 = Object.create(null);
|
||||
const byGroupV2Id = Object.create(null);
|
||||
|
@ -524,9 +519,7 @@ export class ConversationController {
|
|||
if (!existing) {
|
||||
byUuid[uuid] = conversation;
|
||||
} else {
|
||||
window.log.warn(
|
||||
`checkForConflicts: Found conflict with uuid ${uuid}`
|
||||
);
|
||||
log.warn(`checkForConflicts: Found conflict with uuid ${uuid}`);
|
||||
|
||||
// Keep the newer one if it has an e164, otherwise keep existing
|
||||
if (conversation.get('e164')) {
|
||||
|
@ -554,7 +547,7 @@ export class ConversationController {
|
|||
existing.get('uuid') &&
|
||||
conversation.get('uuid') !== existing.get('uuid')
|
||||
) {
|
||||
window.log.warn(
|
||||
log.warn(
|
||||
`checkForConflicts: Found two matches on e164 ${e164} with different truthy UUIDs. Dropping e164 on older.`
|
||||
);
|
||||
|
||||
|
@ -566,9 +559,7 @@ export class ConversationController {
|
|||
continue;
|
||||
}
|
||||
|
||||
window.log.warn(
|
||||
`checkForConflicts: Found conflict with e164 ${e164}`
|
||||
);
|
||||
log.warn(`checkForConflicts: Found conflict with e164 ${e164}`);
|
||||
|
||||
// Keep the newer one if it has a UUID, otherwise keep existing
|
||||
if (conversation.get('uuid')) {
|
||||
|
@ -605,7 +596,7 @@ export class ConversationController {
|
|||
const logParenthetical = isGroupV1(conversation.attributes)
|
||||
? ' (derived from a GV1 group ID)'
|
||||
: '';
|
||||
window.log.warn(
|
||||
log.warn(
|
||||
`checkForConflicts: Found conflict with group V2 ID ${groupV2Id}${logParenthetical}`
|
||||
);
|
||||
|
||||
|
@ -625,7 +616,7 @@ export class ConversationController {
|
|||
}
|
||||
}
|
||||
|
||||
window.log.info('checkForConflicts: complete!');
|
||||
log.info('checkForConflicts: complete!');
|
||||
}
|
||||
|
||||
async combineConversations(
|
||||
|
@ -645,14 +636,14 @@ export class ConversationController {
|
|||
const obsoleteId = obsolete.get('id');
|
||||
const obsoleteUuid = obsolete.get('uuid');
|
||||
const currentId = current.get('id');
|
||||
window.log.warn('combineConversations: Combining two conversations', {
|
||||
log.warn('combineConversations: Combining two conversations', {
|
||||
obsolete: obsoleteId,
|
||||
current: currentId,
|
||||
});
|
||||
|
||||
if (conversationType === 'private' && obsoleteUuid) {
|
||||
if (!current.get('profileKey') && obsolete.get('profileKey')) {
|
||||
window.log.warn(
|
||||
log.warn(
|
||||
'combineConversations: Copying profile key from old to new contact'
|
||||
);
|
||||
|
||||
|
@ -663,7 +654,7 @@ export class ConversationController {
|
|||
}
|
||||
}
|
||||
|
||||
window.log.warn(
|
||||
log.warn(
|
||||
'combineConversations: Delete all sessions tied to old conversationId'
|
||||
);
|
||||
const ourUuid = window.textsecure.storage.user.getCheckedUuid();
|
||||
|
@ -681,7 +672,7 @@ export class ConversationController {
|
|||
})
|
||||
);
|
||||
|
||||
window.log.warn(
|
||||
log.warn(
|
||||
'combineConversations: Delete all identity information tied to old conversationId'
|
||||
);
|
||||
|
||||
|
@ -691,7 +682,7 @@ export class ConversationController {
|
|||
);
|
||||
}
|
||||
|
||||
window.log.warn(
|
||||
log.warn(
|
||||
'combineConversations: Ensure that all V1 groups have new conversationId instead of old'
|
||||
);
|
||||
const groups = await this.getAllGroupsInvolvingId(obsoleteId);
|
||||
|
@ -709,23 +700,23 @@ export class ConversationController {
|
|||
|
||||
// Note: we explicitly don't want to update V2 groups
|
||||
|
||||
window.log.warn(
|
||||
log.warn(
|
||||
'combineConversations: Delete the obsolete conversation from the database'
|
||||
);
|
||||
await removeConversation(obsoleteId, {
|
||||
Conversation: window.Whisper.Conversation,
|
||||
});
|
||||
|
||||
window.log.warn('combineConversations: Update messages table');
|
||||
log.warn('combineConversations: Update messages table');
|
||||
await migrateConversationMessages(obsoleteId, currentId);
|
||||
|
||||
window.log.warn(
|
||||
log.warn(
|
||||
'combineConversations: Eliminate old conversation from ConversationController lookups'
|
||||
);
|
||||
this._conversations.remove(obsolete);
|
||||
this._conversations.resetLookups();
|
||||
|
||||
window.log.warn('combineConversations: Complete!', {
|
||||
log.warn('combineConversations: Complete!', {
|
||||
obsolete: obsoleteId,
|
||||
current: currentId,
|
||||
});
|
||||
|
@ -800,7 +791,7 @@ export class ConversationController {
|
|||
}
|
||||
|
||||
async load(): Promise<void> {
|
||||
window.log.info('ConversationController: starting initial fetch');
|
||||
log.info('ConversationController: starting initial fetch');
|
||||
|
||||
if (this._conversations.length) {
|
||||
throw new Error('ConversationController: Already loaded!');
|
||||
|
@ -818,7 +809,7 @@ export class ConversationController {
|
|||
);
|
||||
|
||||
if (temporaryConversations.length) {
|
||||
window.log.warn(
|
||||
log.warn(
|
||||
`ConversationController: Removing ${temporaryConversations.length} temporary conversations`
|
||||
);
|
||||
}
|
||||
|
@ -866,21 +857,19 @@ export class ConversationController {
|
|||
conversation.set({ e164: undefined });
|
||||
updateConversation(conversation.attributes);
|
||||
|
||||
window.log.info(
|
||||
`Cleaning up conversation(${uuid}) with invalid e164`
|
||||
);
|
||||
log.info(`Cleaning up conversation(${uuid}) with invalid e164`);
|
||||
}
|
||||
} catch (error) {
|
||||
window.log.error(
|
||||
log.error(
|
||||
'ConversationController.load/map: Failed to prepare a conversation',
|
||||
error && error.stack ? error.stack : error
|
||||
);
|
||||
}
|
||||
})
|
||||
);
|
||||
window.log.info('ConversationController: done with initial fetch');
|
||||
log.info('ConversationController: done with initial fetch');
|
||||
} catch (error) {
|
||||
window.log.error(
|
||||
log.error(
|
||||
'ConversationController: initial fetch failed',
|
||||
error && error.stack ? error.stack : error
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue