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

@ -1,6 +1,8 @@
// Copyright 2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import * as log from '../logging/log';
export type SoundOpts = {
loop?: boolean;
src: string;
@ -29,7 +31,7 @@ export class Sound {
const decodedBuffer = await this.context.decodeAudioData(buffer);
Sound.sounds.set(this.src, decodedBuffer);
} catch (err) {
window.log.error(`Sound error: ${err}`);
log.error(`Sound error: ${err}`);
return;
}
}

View file

@ -2,6 +2,7 @@
// SPDX-License-Identifier: AGPL-3.0-only
import * as Errors from '../types/errors';
import * as log from '../logging/log';
type EntryType = Readonly<{
value: number;
@ -21,7 +22,7 @@ export class StartupQueue {
}
public flush(): void {
window.log.info('StartupQueue: Processing', this.map.size, 'actions');
log.info('StartupQueue: Processing', this.map.size, 'actions');
const values = Array.from(this.map.values());
this.map.clear();
@ -30,7 +31,7 @@ export class StartupQueue {
try {
callback();
} catch (error) {
window.log.error(
log.error(
'StartupQueue: Failed to process item due to error',
Errors.toLogFormat(error)
);

View file

@ -4,6 +4,7 @@
import PQueue from 'p-queue';
import { sleep } from './sleep';
import * as log from '../logging/log';
declare global {
// We want to extend `window`'s properties, so we need an interface.
@ -92,9 +93,7 @@ export function createBatcher<ItemType>(
}
async function flushAndWait() {
window.log.info(
`Flushing ${options.name} batcher items.length=${items.length}`
);
log.info(`Flushing ${options.name} batcher items.length=${items.length}`);
while (anyPending()) {
_kickBatchOff();
@ -104,7 +103,7 @@ export function createBatcher<ItemType>(
await queue.onIdle();
}
}
window.log.info(`Flushing complete ${options.name} for batcher`);
log.info(`Flushing complete ${options.name} for batcher`);
}
batcher = {

View file

@ -4,6 +4,7 @@
import { LocalizerType } from '../types/Util';
import { CallMode } from '../types/Calling';
import { missingCaseError } from './missingCaseError';
import * as log from '../logging/log';
type DirectCallNotificationType = {
callMode: CallMode.Direct;
@ -102,7 +103,7 @@ export function getCallingNotificationText(
case CallMode.Group:
return getGroupCallNotificationText(notification, i18n);
default:
window.log.error(
log.error(
`getCallingNotificationText: missing case ${missingCaseError(
notification
)}`
@ -152,7 +153,7 @@ export function getCallingIcon(
case CallMode.Group:
return 'video';
default:
window.log.error(
log.error(
`getCallingNotificationText: missing case ${missingCaseError(
notification
)}`

View file

@ -32,6 +32,7 @@ import { assert } from './assert';
import * as durations from './durations';
import { isPhoneNumberSharingEnabled } from './isPhoneNumberSharingEnabled';
import { parseE164FromSignalDotMeHash } from './sgnlHref';
import * as log from '../logging/log';
type ThemeType = 'light' | 'dark' | 'system';
type NotificationSettingType = 'message' | 'name' | 'count' | 'off';
@ -391,13 +392,11 @@ export function createIPCEvents(
showStickerPack: (packId, key) => {
// We can get these events even if the user has never linked this instance.
if (!window.Signal.Util.Registration.everDone()) {
window.log.warn('showStickerPack: Not registered, returning early');
log.warn('showStickerPack: Not registered, returning early');
return;
}
if (window.isShowingModal) {
window.log.warn(
'showStickerPack: Already showing modal, returning early'
);
log.warn('showStickerPack: Already showing modal, returning early');
return;
}
try {
@ -424,7 +423,7 @@ export function createIPCEvents(
});
} catch (error) {
window.isShowingModal = false;
window.log.error(
log.error(
'showStickerPack: Ran into an error!',
error && error.stack ? error.stack : error
);
@ -442,19 +441,17 @@ export function createIPCEvents(
showGroupViaLink: async hash => {
// We can get these events even if the user has never linked this instance.
if (!window.Signal.Util.Registration.everDone()) {
window.log.warn('showGroupViaLink: Not registered, returning early');
log.warn('showGroupViaLink: Not registered, returning early');
return;
}
if (window.isShowingModal) {
window.log.warn(
'showGroupViaLink: Already showing modal, returning early'
);
log.warn('showGroupViaLink: Already showing modal, returning early');
return;
}
try {
await window.Signal.Groups.joinViaLink(hash);
} catch (error) {
window.log.error(
log.error(
'showGroupViaLink: Ran into an error!',
error && error.stack ? error.stack : error
);
@ -474,7 +471,7 @@ export function createIPCEvents(
},
showConversationViaSignalDotMe(hash: string) {
if (!window.Signal.Util.Registration.everDone()) {
window.log.info(
log.info(
'showConversationViaSignalDotMe: Not registered, returning early'
);
return;
@ -486,9 +483,9 @@ export function createIPCEvents(
return;
}
window.log.info('showConversationViaSignalDotMe: invalid E164');
log.info('showConversationViaSignalDotMe: invalid E164');
if (window.isShowingModal) {
window.log.info(
log.info(
'showConversationViaSignalDotMe: a modal is already showing. Doing nothing'
);
} else {
@ -497,7 +494,7 @@ export function createIPCEvents(
},
unknownSignalLink: () => {
window.log.warn('unknownSignalLink: Showing error dialog');
log.warn('unknownSignalLink: Showing error dialog');
showUnknownSgnlLinkModal();
},

View file

@ -3,6 +3,7 @@
import { DeleteModel } from '../messageModifiers/Deletes';
import { MessageModel } from '../models/messages';
import * as log from '../logging/log';
const ONE_DAY = 24 * 60 * 60 * 1000;
@ -19,7 +20,7 @@ export async function deleteForEveryone(
const delta = Math.abs(doe.get('serverTimestamp') - messageTimestamp);
if (delta > ONE_DAY) {
window.log.info('Received late DOE. Dropping.', {
log.info('Received late DOE. Dropping.', {
fromId: doe.get('fromId'),
targetSentTimestamp: doe.get('targetSentTimestamp'),
messageServerTimestamp: message.get('serverTimestamp'),

View file

@ -19,6 +19,7 @@ import {
} from './zkgroup';
import { getSendOptions } from './getSendOptions';
import { isMe } from './whatTypeOfConversation';
import * as log from '../logging/log';
export async function getProfile(
providedUuid?: string,
@ -36,7 +37,7 @@ export async function getProfile(
});
const c = window.ConversationController.get(id);
if (!c) {
window.log.error('getProfile: failed to find conversation; doing nothing');
log.error('getProfile: failed to find conversation; doing nothing');
return;
}
@ -73,7 +74,7 @@ export async function getProfile(
profileKeyVersionHex &&
!existingProfileKeyCredential
) {
window.log.info('Generating request...');
log.info('Generating request...');
({
requestHex: profileKeyCredentialRequestHex,
context: profileCredentialRequestContext,
@ -98,7 +99,7 @@ export async function getProfile(
});
} catch (error) {
if (error.code === 401 || error.code === 403) {
window.log.info(
log.info(
`Setting sealedSender to DISABLED for conversation ${c.idForLogging()}`
);
c.set({ sealedSender: SEALED_SENDER.DISABLED });
@ -134,7 +135,7 @@ export async function getProfile(
const accessKey = c.get('accessKey');
if (profile.unrestrictedUnidentifiedAccess && profile.unidentifiedAccess) {
window.log.info(
log.info(
`Setting sealedSender to UNRESTRICTED for conversation ${c.idForLogging()}`
);
c.set({
@ -147,14 +148,14 @@ export async function getProfile(
);
if (haveCorrectKey) {
window.log.info(
log.info(
`Setting sealedSender to ENABLED for conversation ${c.idForLogging()}`
);
c.set({
sealedSender: SEALED_SENDER.ENABLED,
});
} else {
window.log.info(
log.info(
`Setting sealedSender to DISABLED for conversation ${c.idForLogging()}`
);
c.set({
@ -162,7 +163,7 @@ export async function getProfile(
});
}
} else {
window.log.info(
log.info(
`Setting sealedSender to DISABLED for conversation ${c.idForLogging()}`
);
c.set({
@ -225,14 +226,14 @@ export async function getProfile(
case 403:
throw error;
case 404:
window.log.warn(
log.warn(
`getProfile failure: failed to find a profile for ${c.idForLogging()}`,
error && error.stack ? error.stack : error
);
c.setUnregistered();
return;
default:
window.log.warn(
log.warn(
'getProfile failure:',
c.idForLogging(),
error && error.stack ? error.stack : error
@ -244,7 +245,7 @@ export async function getProfile(
try {
await c.setEncryptedProfileName(profile.name);
} catch (error) {
window.log.warn(
log.warn(
'getProfile decryption failure:',
c.idForLogging(),
error && error.stack ? error.stack : error
@ -259,9 +260,7 @@ export async function getProfile(
await c.setProfileAvatar(profile.avatar);
} catch (error) {
if (error.code === 403 || error.code === 404) {
window.log.info(
`Clearing profile avatar for conversation ${c.idForLogging()}`
);
log.info(`Clearing profile avatar for conversation ${c.idForLogging()}`);
c.set({
profileAvatar: null,
});

View file

@ -4,6 +4,7 @@
import { isNumber } from 'lodash';
import { CallbackResultType } from '../textsecure/Types.d';
import dataInterface from '../sql/Client';
import * as log from '../logging/log';
const { insertSentProto } = dataInterface;
@ -105,7 +106,7 @@ async function handleMessageSendResult(
conversation &&
conversation.get('sealedSender') !== SEALED_SENDER.DISABLED
) {
window.log.info(
log.info(
`Setting sealedSender to DISABLED for conversation ${conversation.idForLogging()}`
);
conversation.set({
@ -125,14 +126,14 @@ async function handleMessageSendResult(
conversation.get('sealedSender') === SEALED_SENDER.UNKNOWN
) {
if (conversation.get('accessKey')) {
window.log.info(
log.info(
`Setting sealedSender to ENABLED for conversation ${conversation.idForLogging()}`
);
conversation.set({
sealedSender: SEALED_SENDER.ENABLED,
});
} else {
window.log.info(
log.info(
`Setting sealedSender to UNRESTRICTED for conversation ${conversation.idForLogging()}`
);
conversation.set({
@ -162,7 +163,7 @@ async function maybeSaveToSendLog(
}
if (!isNumber(contentHint) || !contentProto || !recipients || !timestamp) {
window.log.warn(
log.warn(
`handleMessageSend: Missing necessary information to save to log for ${sendType} message ${timestamp}`
);
return;
@ -170,7 +171,7 @@ async function maybeSaveToSendLog(
const identifiers = Object.keys(recipients);
if (identifiers.length === 0) {
window.log.warn(
log.warn(
`handleMessageSend: ${sendType} message ${timestamp} had no recipients`
);
return;

View file

@ -27,6 +27,7 @@ import {
} from '../textsecure/messageReceiverEvents';
import { SignalService as Proto } from '../protobuf';
import * as log from '../logging/log';
// Entrypoints
@ -41,19 +42,17 @@ export async function onRetryRequest(event: RetryRequestEvent): Promise<void> {
} = retryRequest;
const logId = `${requesterUuid}.${requesterDevice} ${sentAt}.${senderDevice}`;
window.log.info(`onRetryRequest/${logId}: Starting...`);
log.info(`onRetryRequest/${logId}: Starting...`);
if (!RemoteConfig.isEnabled('desktop.senderKey.retry')) {
window.log.warn(
log.warn(
`onRetryRequest/${logId}: Feature flag disabled, returning early.`
);
return;
}
if (window.RETRY_DELAY) {
window.log.warn(
`onRetryRequest/${logId}: Delaying because RETRY_DELAY is set...`
);
log.warn(`onRetryRequest/${logId}: Delaying because RETRY_DELAY is set...`);
await new Promise(resolve => setTimeout(resolve, 5000));
}
@ -66,14 +65,14 @@ export async function onRetryRequest(event: RetryRequestEvent): Promise<void> {
'retryRespondMaxAge'
);
} catch (error) {
window.log.warn(
log.warn(
`onRetryRequest/${logId}: Failed to parse integer from desktop.retryRespondMaxAge feature flag`,
error && error.stack ? error.stack : error
);
}
if (isOlderThan(sentAt, retryRespondMaxAge)) {
window.log.info(
log.info(
`onRetryRequest/${logId}: Message is too old, refusing to send again.`
);
await sendDistributionMessageOrNullMessage(logId, retryRequest);
@ -87,12 +86,12 @@ export async function onRetryRequest(event: RetryRequestEvent): Promise<void> {
});
if (!sentProto) {
window.log.info(`onRetryRequest/${logId}: Did not find sent proto`);
log.info(`onRetryRequest/${logId}: Did not find sent proto`);
await sendDistributionMessageOrNullMessage(logId, retryRequest);
return;
}
window.log.info(`onRetryRequest/${logId}: Resending message`);
log.info(`onRetryRequest/${logId}: Resending message`);
await archiveSessionOnMatch(retryRequest);
const { contentHint, messageIds, proto, timestamp } = sentProto;
@ -130,9 +129,7 @@ function maybeShowDecryptionToast(logId: string) {
return;
}
window.log.info(
`maybeShowDecryptionToast/${logId}: Showing decryption error toast`
);
log.info(`maybeShowDecryptionToast/${logId}: Showing decryption error toast`);
window.Whisper.ToastView.show(
window.Whisper.DecryptionErrorToast,
document.getElementsByClassName('conversation-stack')[0]
@ -146,7 +143,7 @@ export async function onDecryptionError(
const { senderUuid, senderDevice, timestamp } = decryptionError;
const logId = `${senderUuid}.${senderDevice} ${timestamp}`;
window.log.info(`onDecryptionError/${logId}: Starting...`);
log.info(`onDecryptionError/${logId}: Starting...`);
const conversation = window.ConversationController.getOrCreate(
senderUuid,
@ -167,7 +164,7 @@ export async function onDecryptionError(
await startAutomaticSessionReset(decryptionError);
}
window.log.info(`onDecryptionError/${logId}: ...complete`);
log.info(`onDecryptionError/${logId}: ...complete`);
}
// Helpers
@ -194,7 +191,7 @@ async function archiveSessionOnMatch({
const session = await window.textsecure.storage.protocol.loadSession(address);
if (session && session.currentRatchetKeyMatches(ratchetKey)) {
window.log.info(
log.info(
'archiveSessionOnMatch: Matching device and ratchetKey, archiving session'
);
await window.textsecure.storage.protocol.archiveSession(address);
@ -207,7 +204,7 @@ async function sendDistributionMessageOrNullMessage(
): Promise<void> {
const { groupId, requesterUuid } = options;
let sentDistributionMessage = false;
window.log.info(`sendDistributionMessageOrNullMessage/${logId}: Starting...`);
log.info(`sendDistributionMessageOrNullMessage/${logId}: Starting...`);
await archiveSessionOnMatch(options);
@ -227,7 +224,7 @@ async function sendDistributionMessageOrNullMessage(
}
if (group && distributionId) {
window.log.info(
log.info(
`sendDistributionMessageOrNullMessage/${logId}: Found matching group, sending sender key distribution message`
);
@ -248,7 +245,7 @@ async function sendDistributionMessageOrNullMessage(
}
sentDistributionMessage = true;
} catch (error) {
window.log.error(
log.error(
`sendDistributionMessageOrNullMessage/${logId}: Failed to send sender key distribution message`,
error && error.stack ? error.stack : error
);
@ -257,7 +254,7 @@ async function sendDistributionMessageOrNullMessage(
}
if (!sentDistributionMessage) {
window.log.info(
log.info(
`sendDistributionMessageOrNullMessage/${logId}: Did not send distribution message, sending null message`
);
@ -274,7 +271,7 @@ async function sendDistributionMessageOrNullMessage(
throw result.errors[0];
}
} catch (error) {
window.log.error(
log.error(
`maybeSendDistributionMessage/${logId}: Failed to send null message`,
error && error.stack ? error.stack : error
);
@ -301,7 +298,7 @@ async function getRetryConversation({
Message: window.Whisper.Message,
});
if (!message) {
window.log.warn(
log.warn(
`maybeAddSenderKeyDistributionMessage/${logId}: Unable to find message ${messageId}`
);
// Fail over to requested groupId
@ -332,7 +329,7 @@ async function maybeAddSenderKeyDistributionMessage({
});
if (!conversation) {
window.log.warn(
log.warn(
`maybeAddSenderKeyDistributionMessage/${logId}: Unable to find conversation`
);
return {
@ -387,7 +384,7 @@ async function requestResend(decryptionError: DecryptionErrorEventData) {
} = decryptionError;
const logId = `${senderUuid}.${senderDevice} ${timestamp}`;
window.log.info(`requestResend/${logId}: Starting...`, {
log.info(`requestResend/${logId}: Starting...`, {
cipherTextBytesLength: cipherTextBytes?.byteLength,
cipherTextType,
contentHint,
@ -408,7 +405,7 @@ async function requestResend(decryptionError: DecryptionErrorEventData) {
// 2. Send resend request
if (!cipherTextBytes || !isNumber(cipherTextType)) {
window.log.warn(
log.warn(
`requestResend/${logId}: Missing cipherText information, failing over to automatic reset`
);
startAutomaticSessionReset(decryptionError);
@ -438,7 +435,7 @@ async function requestResend(decryptionError: DecryptionErrorEventData) {
throw result.errors[0];
}
} catch (error) {
window.log.error(
log.error(
`requestResend/${logId}: Failed to send retry request, failing over to automatic reset`,
error && error.stack ? error.stack : error
);
@ -455,7 +452,7 @@ async function requestResend(decryptionError: DecryptionErrorEventData) {
const { retryPlaceholders } = window.Signal.Services;
strictAssert(retryPlaceholders, 'requestResend: adding placeholder');
window.log.info(`requestResend/${logId}: Adding placeholder`);
log.info(`requestResend/${logId}: Adding placeholder`);
const state = window.reduxStore.getState();
const selectedId = state.conversations.selectedConversationId;
@ -476,15 +473,11 @@ async function requestResend(decryptionError: DecryptionErrorEventData) {
// This message cannot be resent. We'll show no error and trust the other side to
// reset their session.
if (contentHint === ContentHint.IMPLICIT) {
window.log.info(
`requestResend/${logId}: contentHint is IMPLICIT, doing nothing.`
);
log.info(`requestResend/${logId}: contentHint is IMPLICIT, doing nothing.`);
return;
}
window.log.warn(
`requestResend/${logId}: No content hint, adding error immediately`
);
log.warn(`requestResend/${logId}: No content hint, adding error immediately`);
conversation.queueJob('addDeliveryIssue', async () => {
conversation.addDeliveryIssue({
receivedAt: receivedAtDate,
@ -518,7 +511,7 @@ function startAutomaticSessionReset(decryptionError: DecryptionErrorEventData) {
const { senderUuid, senderDevice, timestamp } = decryptionError;
const logId = `${senderUuid}.${senderDevice} ${timestamp}`;
window.log.info(`startAutomaticSessionReset/${logId}: Starting...`);
log.info(`startAutomaticSessionReset/${logId}: Starting...`);
scheduleSessionReset(senderUuid, senderDevice);
@ -527,7 +520,7 @@ function startAutomaticSessionReset(decryptionError: DecryptionErrorEventData) {
});
if (!conversationId) {
window.log.warn(
log.warn(
'onLightSessionReset: No conversation id, cannot add message to timeline'
);
return;
@ -535,7 +528,7 @@ function startAutomaticSessionReset(decryptionError: DecryptionErrorEventData) {
const conversation = window.ConversationController.get(conversationId);
if (!conversation) {
window.log.warn(
log.warn(
'onLightSessionReset: No conversation, cannot add message to timeline'
);
return;

View file

@ -3,13 +3,14 @@
import { Environment, getEnvironment } from '../environment';
import { isInPast } from './timestamp';
import * as log from '../logging/log';
const ONE_DAY_MS = 86400 * 1000;
const NINETY_ONE_DAYS = 91 * ONE_DAY_MS;
const THIRTY_ONE_DAYS = 31 * ONE_DAY_MS;
export function hasExpired(): boolean {
const { getExpiration, log } = window;
const { getExpiration } = window;
let buildExpiration = 0;

View file

@ -5,6 +5,7 @@ import * as React from 'react';
import { ActionCreatorsMapObject, bindActionCreators } from 'redux';
import { useDispatch } from 'react-redux';
import { first, last, noop } from 'lodash';
import * as log from '../../logging/log';
export function usePrevious<T>(initialValue: T, currentValue: T): T {
const previousValueRef = React.useRef<T>(initialValue);
@ -86,7 +87,7 @@ export function useIntersectionObserver(): [
const observer = new IntersectionObserver(entries => {
if (entries.length !== 1) {
window.log.error(
log.error(
'IntersectionObserverWrapper was observing the wrong number of elements'
);
return;

View file

@ -5,6 +5,7 @@ import { debounce, isNumber } from 'lodash';
import { strictAssert } from './assert';
import Data from '../sql/Client';
import * as log from '../logging/log';
let receivedAtCounter: number | undefined;
@ -18,26 +19,22 @@ export async function initializeMessageCounter(): Promise<void> {
const dbCounter = await Data.getMaxMessageCounter();
if (isNumber(dbCounter) && isNumber(storedCounter)) {
window.log.info(
'initializeMessageCounter: picking max of db/stored counters'
);
log.info('initializeMessageCounter: picking max of db/stored counters');
receivedAtCounter = Math.max(dbCounter, storedCounter);
if (receivedAtCounter !== storedCounter) {
window.log.warn(
'initializeMessageCounter: mismatch between db/stored counters'
);
log.warn('initializeMessageCounter: mismatch between db/stored counters');
}
} else if (isNumber(storedCounter)) {
window.log.info('initializeMessageCounter: picking stored counter');
log.info('initializeMessageCounter: picking stored counter');
receivedAtCounter = storedCounter;
} else if (isNumber(dbCounter)) {
window.log.info(
log.info(
'initializeMessageCounter: picking fallback counter from the database'
);
receivedAtCounter = dbCounter;
} else {
window.log.info('initializeMessageCounter: defaulting to Date.now()');
log.info('initializeMessageCounter: defaulting to Date.now()');
receivedAtCounter = Date.now();
}

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,8 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import * as log from '../logging/log';
export async function longRunningTaskWrapper<T>({
name,
idForLogging,
@ -19,7 +21,7 @@ export async function longRunningTaskWrapper<T>({
let progressView: Backbone.View | undefined;
let spinnerStart;
let progressTimeout: NodeJS.Timeout | undefined = setTimeout(() => {
window.log.info(`longRunningTaskWrapper/${idLog}: Creating spinner`);
log.info(`longRunningTaskWrapper/${idLog}: Creating spinner`);
// Note: this component uses a portal to render itself into the top-level DOM. No
// need to attach it to the DOM here.
@ -33,11 +35,9 @@ export async function longRunningTaskWrapper<T>({
// Note: any task we put here needs to have its own safety valve; this function will
// show a spinner until it's done
try {
window.log.info(`longRunningTaskWrapper/${idLog}: Starting task`);
log.info(`longRunningTaskWrapper/${idLog}: Starting task`);
const result = await task();
window.log.info(
`longRunningTaskWrapper/${idLog}: Task completed successfully`
);
log.info(`longRunningTaskWrapper/${idLog}: Task completed successfully`);
if (progressTimeout) {
clearTimeout(progressTimeout);
@ -46,7 +46,7 @@ export async function longRunningTaskWrapper<T>({
if (progressView) {
const now = Date.now();
if (spinnerStart && now - spinnerStart < ONE_SECOND) {
window.log.info(
log.info(
`longRunningTaskWrapper/${idLog}: Spinner shown for less than second, showing for another second`
);
await window.Signal.Util.sleep(ONE_SECOND);
@ -57,7 +57,7 @@ export async function longRunningTaskWrapper<T>({
return result;
} catch (error) {
window.log.error(
log.error(
`longRunningTaskWrapper/${idLog}: Error!`,
error && error.stack ? error.stack : error
);
@ -72,7 +72,7 @@ export async function longRunningTaskWrapper<T>({
}
if (!suppressErrorDialog) {
window.log.info(`longRunningTaskWrapper/${idLog}: Showing error dialog`);
log.info(`longRunningTaskWrapper/${idLog}: Showing error dialog`);
// Note: this component uses a portal to render itself into the top-level DOM. No
// need to attach it to the DOM here.

View file

@ -5,6 +5,7 @@ import { ConversationAttributesType } from '../model-types.d';
import { sendReadReceiptsFor } from './sendReadReceiptsFor';
import { hasErrors } from '../state/selectors/message';
import { readSyncJobQueue } from '../jobs/readSyncJobQueue';
import * as log from '../logging/log';
export async function markConversationRead(
conversationAttrs: ConversationAttributesType,
@ -27,7 +28,7 @@ export async function markConversationRead(
),
]);
window.log.info('markConversationRead', {
log.info('markConversationRead', {
conversationId,
newestUnreadId,
unreadMessages: unreadMessages.length,
@ -102,11 +103,11 @@ export async function markConversationRead(
}> = [...unreadMessagesSyncData, ...unreadReactionSyncData.values()];
if (readSyncs.length && options.sendReadReceipts) {
window.log.info(`Sending ${readSyncs.length} read syncs`);
log.info(`Sending ${readSyncs.length} read syncs`);
// Because syncReadMessages sends to our other devices, and sendReadReceipts goes
// to a contact, we need accessKeys for both.
if (window.ConversationController.areWePrimaryDevice()) {
window.log.warn(
log.warn(
'markConversationRead: We are primary device; not sending read syncs'
);
} else {

View file

@ -4,13 +4,14 @@
import { MessageAttributesType } from '../model-types.d';
import { createBatcher } from './batcher';
import { createWaitBatcher } from './waitBatcher';
import * as log from '../logging/log';
const updateMessageBatcher = createBatcher<MessageAttributesType>({
name: 'messageBatcher.updateMessageBatcher',
wait: 75,
maxSize: 50,
processBatch: async (messageAttrs: Array<MessageAttributesType>) => {
window.log.info('updateMessageBatcher', messageAttrs.length);
log.info('updateMessageBatcher', messageAttrs.length);
await window.Signal.Data.saveMessages(messageAttrs);
},
});
@ -34,7 +35,7 @@ export const saveNewMessageBatcher = createWaitBatcher<MessageAttributesType>({
wait: 75,
maxSize: 30,
processBatch: async (messageAttrs: Array<MessageAttributesType>) => {
window.log.info('saveNewMessageBatcher', messageAttrs.length);
log.info('saveNewMessageBatcher', messageAttrs.length);
await window.Signal.Data.saveMessages(messageAttrs, {
forceSave: true,
});

View file

@ -3,6 +3,7 @@
import { z } from 'zod';
import { groupBy } from 'lodash';
import * as log from '../logging/log';
const retryItemSchema = z
.object({
@ -55,7 +56,7 @@ export class RetryPlaceholders {
window.storage.get(STORAGE_KEY, new Array<RetryItemType>())
);
if (!parsed.success) {
window.log.warn(
log.warn(
`RetryPlaceholders.constructor: Data fetched from storage did not match schema: ${JSON.stringify(
parsed.error.flatten()
)}`
@ -68,7 +69,7 @@ export class RetryPlaceholders {
this.byMessage = this.makeByMessageLookup();
this.retryReceiptLifespan = options.retryReceiptLifespan || HOUR;
window.log.info(
log.info(
`RetryPlaceholders.constructor: Started with ${this.items.length} items, lifespan of ${this.retryReceiptLifespan}`
);
}
@ -145,7 +146,7 @@ export class RetryPlaceholders {
}
}
window.log.info(
log.info(
`RetryPlaceholders.getExpiredAndRemove: Found ${result.length} expired items`
);
@ -168,7 +169,7 @@ export class RetryPlaceholders {
});
if (changed > 0) {
window.log.info(
log.info(
`RetryPlaceholders.findByConversationAndMarkOpened: Updated ${changed} items for conversation ${conversationId}`
);

View file

@ -6,6 +6,7 @@ import { ConversationType } from '../state/ducks/conversations';
import { UUID } from '../types/UUID';
import { assert } from './assert';
import * as log from '../logging/log';
export async function generateSecurityNumber(
ourNumber: string,
@ -56,7 +57,7 @@ export async function generateSecurityNumberBlock(
}
if (!contact.e164) {
window.log.error(
log.error(
'generateSecurityNumberBlock: Attempted to generate security number for contact with no e164'
);
return [];

View file

@ -6,6 +6,7 @@ import { ConversationAttributesType } from '../model-types.d';
import { getSendOptions } from './getSendOptions';
import { handleMessageSend } from './handleMessageSend';
import { isConversationAccepted } from './isConversationAccepted';
import * as log from '../logging/log';
type ReceiptSpecType = {
messageId: string;
@ -27,7 +28,7 @@ export async function sendReadReceiptsFor(
window.Events.getReadReceiptSetting() &&
isConversationAccepted(conversationAttrs)
) {
window.log.info(`Sending ${items.length} read receipts`);
log.info(`Sending ${items.length} read receipts`);
const sendOptions = await getSendOptions(conversationAttrs);
const receiptsBySender = groupBy(items, 'senderId');

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({

View file

@ -4,6 +4,7 @@
import PQueue from 'p-queue';
import { sleep } from './sleep';
import * as log from '../logging/log';
declare global {
// We want to extend `window`'s properties, so we need an interface.
@ -19,12 +20,12 @@ declare global {
window.waitBatchers = [];
window.flushAllWaitBatchers = async () => {
window.log.info('waitBatcher#flushAllWaitBatchers');
log.info('waitBatcher#flushAllWaitBatchers');
await Promise.all(window.waitBatchers.map(item => item.flushAndWait()));
};
window.waitForAllWaitBatchers = async () => {
window.log.info('waitBatcher#waitForAllWaitBatchers');
log.info('waitBatcher#waitForAllWaitBatchers');
await Promise.all(window.waitBatchers.map(item => item.onIdle()));
};
@ -150,7 +151,7 @@ export function createWaitBatcher<ItemType>(
}
async function flushAndWait() {
window.log.info(
log.info(
`Flushing start ${options.name} for waitBatcher ` +
`items.length=${items.length}`
);
@ -169,7 +170,7 @@ export function createWaitBatcher<ItemType>(
}
}
window.log.info(`Flushing complete ${options.name} for waitBatcher`);
log.info(`Flushing complete ${options.name} for waitBatcher`);
}
waitBatcher = {

View file

@ -4,6 +4,7 @@
import { ConversationAttributesType } from '../model-types.d';
import { ConversationType } from '../state/ducks/conversations';
import { base64ToArrayBuffer, fromEncodedBinaryToArrayBuffer } from '../Crypto';
import * as log from '../logging/log';
export enum ConversationTypes {
Me = 'Me',
@ -58,7 +59,7 @@ export function isGroupV2(
base64ToArrayBuffer(groupId).byteLength === window.Signal.Groups.ID_LENGTH
);
} catch (error) {
window.log.error('isGroupV2: Failed to process groupId in base64!');
log.error('isGroupV2: Failed to process groupId in base64!');
return false;
}
}