Import log instead of using it off of window

This commit is contained in:
Josh Perez 2021-09-17 14:27:53 -04:00 committed by GitHub
parent 8eb0dd3116
commit 65ddf0a9e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
155 changed files with 3654 additions and 3433 deletions

View file

@ -52,6 +52,7 @@ import * as RemoteConfig from '../RemoteConfig';
import { strictAssert } from './assert';
import { isGroupV2 } from './whatTypeOfConversation';
import * as log from '../logging/log';
const ERROR_EXPIRED_OR_MISSING_DEVICES = 409;
const ERROR_STALE_DEVICES = 410;
@ -171,7 +172,7 @@ export async function sendContentMessageToGroup({
timestamp,
});
} catch (error) {
window.log.error(
log.error(
`sendToGroup/${logId}: Sender Key send failed, logging, proceeding to normal send`,
error && error.stack ? error.stack : error
);
@ -230,7 +231,7 @@ export async function sendToGroupViaSenderKey(options: {
const { ContentHint } = Proto.UnidentifiedSenderMessage.Message;
const logId = conversation.idForLogging();
window.log.info(
log.info(
`sendToGroupViaSenderKey/${logId}: Starting ${timestamp}, recursion count ${recursionCount}...`
);
@ -269,7 +270,7 @@ export async function sendToGroupViaSenderKey(options: {
// 1. Add sender key info if we have none, or clear out if it's too old
const THIRTY_DAYS = 30 * DAY;
if (!attributes.senderKeyInfo) {
window.log.info(
log.info(
`sendToGroupViaSenderKey/${logId}: Adding initial sender key info`
);
conversation.set({
@ -282,7 +283,7 @@ export async function sendToGroupViaSenderKey(options: {
window.Signal.Data.updateConversation(attributes);
} else if (isOlderThan(attributes.senderKeyInfo.createdAtDate, THIRTY_DAYS)) {
const { createdAtDate } = attributes.senderKeyInfo;
window.log.info(
log.info(
`sendToGroupViaSenderKey/${logId}: Resetting sender key; ${createdAtDate} is too old`
);
await resetSenderKey(conversation);
@ -335,7 +336,7 @@ export async function sendToGroupViaSenderKey(options: {
const senderKeyRecipients = getUuidsFromDevices(devicesForSenderKey);
const normalSendRecipients = getUuidsFromDevices(devicesForNormalSend);
window.log.info(
log.info(
`sendToGroupViaSenderKey/${logId}:` +
` ${senderKeyRecipients.length} accounts for sender key (${devicesForSenderKey.length} devices),` +
` ${normalSendRecipients.length} accounts for normal send (${devicesForNormalSend.length} devices)`
@ -379,7 +380,7 @@ export async function sendToGroupViaSenderKey(options: {
// 8. If there are new members or new devices in the group, we need to ensure that they
// have our sender key before we send sender key messages to them.
if (newToMemberUuids.length > 0) {
window.log.info(
log.info(
`sendToGroupViaSenderKey/${logId}: Sending sender key to ${
newToMemberUuids.length
} members: ${JSON.stringify(newToMemberUuids)}`
@ -481,7 +482,7 @@ export async function sendToGroupViaSenderKey(options: {
uuids404 || []
);
} else {
window.log.error(
log.error(
`sendToGroupViaSenderKey/${logId}: Server returned unexpected 200 response ${JSON.stringify(
parsed.error.flatten()
)}`
@ -527,7 +528,7 @@ export async function sendToGroupViaSenderKey(options: {
const brokenAccount = window.ConversationController.get(name);
if (brokenAccount) {
window.log.warn(
log.warn(
`sendToGroupViaSenderKey/${logId}: Disabling sealed sender for ${brokenAccount.idForLogging()}`
);
brokenAccount.set({ sealedSender: SEALED_SENDER.DISABLED });
@ -584,14 +585,14 @@ export async function sendToGroupViaSenderKey(options: {
const sentToConversation = window.ConversationController.get(identifier);
if (!sentToConversation) {
window.log.warn(
log.warn(
`sendToGroupViaSenderKey/callback: Unable to find conversation for identifier ${identifier}`
);
return;
}
const recipientUuid = sentToConversation.get('uuid');
if (!recipientUuid) {
window.log.warn(
log.warn(
`sendToGroupViaSenderKey/callback: Conversation ${conversation.idForLogging()} had no UUID`
);
return;
@ -678,7 +679,7 @@ async function markIdentifierUnregistered(identifier: string) {
const uuid = UUID.lookup(identifier);
if (!uuid) {
window.log.warn(`No uuid found for ${identifier}`);
log.warn(`No uuid found for ${identifier}`);
return;
}
@ -722,7 +723,7 @@ async function handle409Response(logId: string, error: Error) {
maxConcurrency: 2,
});
} else {
window.log.error(
log.error(
`handle409Response/${logId}: Server returned unexpected 409 response ${JSON.stringify(
parsed.error.flatten()
)}`
@ -781,7 +782,7 @@ async function handle410Response(
maxConcurrency: 2,
});
} else {
window.log.error(
log.error(
`handle410Response/${logId}: Server returned unexpected 410 response ${JSON.stringify(
parsed.error.flatten()
)}`
@ -915,14 +916,14 @@ function isValidSenderKeyRecipient(
): boolean {
const memberConversation = window.ConversationController.get(uuid);
if (!memberConversation) {
window.log.warn(
log.warn(
`isValidSenderKeyRecipient: Missing conversation model for member ${uuid}`
);
return false;
}
if (!members.has(memberConversation)) {
window.log.info(
log.info(
`isValidSenderKeyRecipient: Sending to ${uuid}, not a group member`
);
return false;
@ -938,9 +939,7 @@ function isValidSenderKeyRecipient(
}
if (memberConversation.isUnregistered()) {
window.log.warn(
`isValidSenderKeyRecipient: Member ${uuid} is unregistered`
);
log.warn(`isValidSenderKeyRecipient: Member ${uuid} is unregistered`);
return false;
}
@ -1034,15 +1033,13 @@ function getOurAddress(): Address {
async function resetSenderKey(conversation: ConversationModel): Promise<void> {
const logId = conversation.idForLogging();
window.log.info(
`resetSenderKey/${logId}: Sender key needs reset. Clearing data...`
);
log.info(`resetSenderKey/${logId}: Sender key needs reset. Clearing data...`);
const {
attributes,
}: { attributes: ConversationAttributesType } = conversation;
const { senderKeyInfo } = attributes;
if (!senderKeyInfo) {
window.log.warn(`resetSenderKey/${logId}: No sender key info`);
log.warn(`resetSenderKey/${logId}: No sender key info`);
return;
}
@ -1088,7 +1085,7 @@ function getAccessKey(
async function fetchKeysForIdentifiers(
identifiers: Array<string>
): Promise<void> {
window.log.info(
log.info(
`fetchKeysForIdentifiers: Fetching keys for ${identifiers.length} identifiers`
);
@ -1099,7 +1096,7 @@ async function fetchKeysForIdentifiers(
),
});
} catch (error) {
window.log.error(
log.error(
'fetchKeysForIdentifiers: Failed to fetch keys:',
error && error.stack ? error.stack : error
);
@ -1110,7 +1107,7 @@ async function fetchKeysForIdentifier(
identifier: string,
devices?: Array<number>
): Promise<void> {
window.log.info(
log.info(
`fetchKeysForIdentifier: Fetching ${
devices || 'all'
} devices for ${identifier}`
@ -1133,7 +1130,7 @@ async function fetchKeysForIdentifier(
getAccessKey(emptyConversation.attributes)
);
if (accessKeyFailed) {
window.log.info(
log.info(
`fetchKeysForIdentifiers: Setting sealedSender to DISABLED for conversation ${emptyConversation.idForLogging()}`
);
emptyConversation.set({