From 65ddf0a9e8ba36be0f7b4b73d1339001aa33ebbc Mon Sep 17 00:00:00 2001 From: Josh Perez <60019601+josh-signal@users.noreply.github.com> Date: Fri, 17 Sep 2021 14:27:53 -0400 Subject: [PATCH] Import log instead of using it off of window --- background.html | 8 - debug_log.html | 1 - debug_log_preload.js | 3 +- js/database.js | 2 +- js/debug_log_start.js | 3 +- js/expiring_messages.js | 22 +- js/expiring_tap_to_view_messages.js | 12 +- js/modules/debug.js | 9 +- js/modules/i18n.js | 7 +- js/modules/idle_detector.js | 4 +- js/modules/indexeddb.js | 10 +- js/modules/messages_data_migrator.js | 2 +- js/modules/types/conversation.js | 2 +- js/notifications.js | 8 +- js/reliable_trigger.js | 2 +- js/rotate_signed_prekey_listener.js | 12 +- js/views/debug_log_view.js | 201 -- js/views/inbox_view.js | 242 --- js/views/install_view.js | 238 --- js/views/phone-input-view.js | 40 - js/views/react_wrapper_view.js | 2 +- js/views/recorder_view.js | 149 -- js/views/standalone_registration_view.js | 106 - libtextsecure/test/_test.js | 6 +- main.js | 6 - preload.js | 30 +- sticker-creator/app/stages/UploadStage.tsx | 2 +- sticker-creator/components/StickerGrid.tsx | 2 +- sticker-creator/preload.js | 4 +- test/_test.js | 6 +- test/setup-test-node.js | 10 +- ts/CI.ts | 9 +- ts/ConversationController.ts | 77 +- ts/Crypto.ts | 5 +- ts/Curve.ts | 3 +- ts/RemoteConfig.ts | 3 +- ts/SignalProtocolStore.ts | 116 +- ts/background.ts | 277 ++- ts/challenge.ts | 55 +- ts/components/CompositionInput.tsx | 3 +- ts/components/GlobalAudioContext.tsx | 14 +- ts/components/GroupCallRemoteParticipants.tsx | 9 +- ts/components/Intl.tsx | 7 +- ts/components/Lightbox.tsx | 3 +- ts/components/Profiler.tsx | 3 +- .../conversation/CallingNotification.tsx | 9 +- .../conversation/ConversationHero.tsx | 3 +- ts/components/conversation/ErrorBoundary.tsx | 3 +- ts/components/conversation/GIF.tsx | 3 +- .../conversation/GroupV1Migration.tsx | 5 +- ts/components/conversation/Message.tsx | 9 +- ts/components/conversation/MessageAudio.tsx | 21 +- ts/components/conversation/MessageDetail.tsx | 13 +- ts/components/conversation/TimelineItem.tsx | 3 +- .../conversation/TimerNotification.tsx | 3 +- .../media-gallery/MediaGridItem.tsx | 3 +- ts/components/emoji/lib.ts | 5 +- ts/groupChange.ts | 21 +- ts/groups.ts | 226 +-- ts/groups/joinViaLink.ts | 15 +- ts/jobs/JobLogger.ts | 2 +- ts/jobs/JobQueue.ts | 7 +- ts/jobs/helpers/commonShouldJobContinue.ts | 2 +- .../helpers/handleCommonJobRequestError.ts | 2 +- ts/jobs/helpers/readAndViewSyncHelpers.ts | 2 +- .../sleepFor413RetryAfterTimeIfApplicable.ts | 2 +- ts/jobs/normalMessageSendJobQueue.ts | 2 +- ts/jobs/readSyncJobQueue.ts | 2 +- ts/jobs/reportSpamJobQueue.ts | 2 +- ts/jobs/viewSyncJobQueue.ts | 2 +- ts/jobs/viewedReceiptsJobQueue.ts | 2 +- ts/linkPreviews/linkPreviewFetch.ts | 47 +- ts/logging/debuglogs.ts | 106 +- ts/logging/log.ts | 30 +- ts/logging/set_up_renderer_logging.ts | 112 +- ts/logging/shared.ts | 9 +- ts/messageModifiers/AttachmentDownloads.ts | 5 +- ts/messageModifiers/Deletes.ts | 11 +- ts/messageModifiers/MessageReceipts.ts | 11 +- ts/messageModifiers/MessageRequests.ts | 13 +- ts/messageModifiers/Reactions.ts | 16 +- ts/messageModifiers/ReadSyncs.ts | 9 +- ts/messageModifiers/ViewOnceOpenSyncs.ts | 9 +- ts/messageModifiers/ViewSyncs.ts | 7 +- ts/models/conversations.ts | 150 +- ts/models/messages.ts | 146 +- ts/routineProfileRefresh.ts | 6 +- ts/services/calling.ts | 176 +- ts/services/groupCredentialFetcher.ts | 19 +- ts/services/networkObserver.ts | 2 +- ts/services/storage.ts | 159 +- ts/services/storageRecordOps.ts | 53 +- ts/shims/deleteAllData.ts | 14 +- ts/shims/textsecure.ts | 5 +- ts/sql/Client.ts | 39 +- ts/sql/Server.ts | 3 +- ts/state/ducks/app.ts | 3 +- ts/state/ducks/calling.ts | 69 +- ts/state/ducks/conversations.ts | 9 +- ts/state/ducks/safetyNumber.ts | 5 +- ts/state/selectors/conversations.ts | 11 +- ts/state/selectors/message.ts | 11 +- ts/state/selectors/search.ts | 7 +- ts/state/smart/CallManager.tsx | 25 +- ts/state/smart/GroupV1MigrationDialog.tsx | 9 +- .../linkPreviews/linkPreviewFetch_test.ts | 3 +- ts/test-node/jobs/JobQueue_test.ts | 2 +- ts/test-node/logging/uploadDebugLogs_test.ts | 12 +- ts/textsecure/AccountManager.ts | 56 +- ts/textsecure/ContactsParser.ts | 3 +- ts/textsecure/MessageReceiver.ts | 197 +- ts/textsecure/OutgoingMessage.ts | 15 +- ts/textsecure/SendMessage.ts | 15 +- ts/textsecure/SocketManager.ts | 57 +- ts/textsecure/Storage.ts | 10 +- ts/textsecure/SyncRequest.ts | 15 +- ts/textsecure/TaskWithTimeout.ts | 5 +- ts/textsecure/Utils.ts | 4 +- ts/textsecure/WebAPI.ts | 35 +- ts/textsecure/WebsocketResources.ts | 27 +- ts/textsecure/getKeysForIdentifier.ts | 3 +- ts/textsecure/storage/Blocked.ts | 13 +- ts/textsecure/storage/User.ts | 7 +- ts/types/Logging.ts | 2 +- ts/types/Stickers.ts | 15 +- ts/util/Sound.ts | 4 +- ts/util/StartupQueue.ts | 5 +- ts/util/batcher.ts | 7 +- ts/util/callingNotification.ts | 5 +- ts/util/createIPCEvents.ts | 25 +- ts/util/deleteForEveryone.ts | 3 +- ts/util/getProfile.ts | 25 +- ts/util/handleMessageSend.ts | 11 +- ts/util/handleRetry.ts | 63 +- ts/util/hasExpired.ts | 3 +- ts/util/hooks/index.ts | 3 +- ts/util/incrementMessageCounter.ts | 15 +- ts/util/lint/exceptions.json | 1784 +++++++++++------ ts/util/longRunningTaskWrapper.ts | 16 +- ts/util/markConversationRead.ts | 7 +- ts/util/messageBatcher.ts | 5 +- ts/util/retryPlaceholders.ts | 9 +- ts/util/safetyNumber.ts | 3 +- ts/util/sendReadReceiptsFor.ts | 3 +- ts/util/sendToGroup.ts | 49 +- ts/util/waitBatcher.ts | 9 +- ts/util/whatTypeOfConversation.ts | 3 +- ts/views/conversation_view.ts | 127 +- ts/views/debug_log_view.ts | 201 ++ ts/views/inbox_view.ts | 233 +++ ts/views/install_view.ts | 237 +++ ts/views/phone_input_view.ts | 38 + ts/views/recorder_view.ts | 143 ++ ts/views/standalone_registration_view.ts | 117 ++ ts/window.d.ts | 28 +- 155 files changed, 3654 insertions(+), 3433 deletions(-) delete mode 100644 js/views/debug_log_view.js delete mode 100644 js/views/inbox_view.js delete mode 100644 js/views/install_view.js delete mode 100644 js/views/phone-input-view.js delete mode 100644 js/views/recorder_view.js delete mode 100644 js/views/standalone_registration_view.js create mode 100644 ts/views/debug_log_view.ts create mode 100644 ts/views/inbox_view.ts create mode 100644 ts/views/install_view.ts create mode 100644 ts/views/phone_input_view.ts create mode 100644 ts/views/recorder_view.ts create mode 100644 ts/views/standalone_registration_view.ts diff --git a/background.html b/background.html index cbeb81d99f..d7b867b4d4 100644 --- a/background.html +++ b/background.html @@ -291,18 +291,10 @@ type="text/javascript" src="js/views/key_verification_view.js" > - - - - - - diff --git a/debug_log_preload.js b/debug_log_preload.js index ed669910b1..be3db5a1f3 100644 --- a/debug_log_preload.js +++ b/debug_log_preload.js @@ -5,7 +5,6 @@ const { ipcRenderer } = require('electron'); const url = require('url'); -const copyText = require('copy-text-to-clipboard'); // It is important to call this as early as possible require('./ts/windows/context'); @@ -25,7 +24,6 @@ setEnvironment(parseEnvironment(config.environment)); window.getVersion = () => config.version; window.theme = config.theme; window.i18n = i18n.setup(locale, localeMessages); -window.copyText = copyText; // got.js appears to need this to successfully submit debug logs to the cloud window.nodeSetImmediate = setImmediate; @@ -37,6 +35,7 @@ window.Backbone = require('backbone'); require('./ts/backbone/views/whisper_view'); require('./ts/backbone/views/toast_view'); require('./ts/logging/set_up_renderer_logging').initialize(); +require('./ts/views/debug_log_view'); window.closeDebugLog = () => ipcRenderer.send('close-debug-log'); window.Backbone = require('backbone'); diff --git a/js/database.js b/js/database.js index d48616adde..d9ecbd4bd0 100644 --- a/js/database.js +++ b/js/database.js @@ -11,7 +11,7 @@ window.Whisper.Database.nolog = true; Whisper.Database.handleDOMException = (prefix, error, reject) => { - window.log.error( + window.SignalWindow.log.error( `${prefix}:`, error && error.name, error && error.message, diff --git a/js/debug_log_start.js b/js/debug_log_start.js index b9a27abf6b..3a81a1d006 100644 --- a/js/debug_log_start.js +++ b/js/debug_log_start.js @@ -2,7 +2,6 @@ // SPDX-License-Identifier: AGPL-3.0-only /* global $: false */ -/* global Whisper: false */ $(document).on('keydown', e => { if (e.keyCode === 27) { @@ -16,5 +15,5 @@ $body.addClass(`${window.theme}-theme`); // got.js appears to need this to successfully submit debug logs to the cloud window.setImmediate = window.nodeSetImmediate; -window.view = new Whisper.DebugLogView(); +window.view = new window.Whisper.DebugLogView(); window.view.$el.appendTo($body); diff --git a/js/expiring_messages.js b/js/expiring_messages.js index 512fe042ab..db50b8d059 100644 --- a/js/expiring_messages.js +++ b/js/expiring_messages.js @@ -13,11 +13,13 @@ async function destroyExpiredMessages() { try { - window.log.info('destroyExpiredMessages: Loading messages...'); + window.SignalWindow.log.info( + 'destroyExpiredMessages: Loading messages...' + ); const messages = await window.Signal.Data.getExpiredMessages({ MessageCollection: Whisper.MessageCollection, }); - window.log.info( + window.SignalWindow.log.info( `destroyExpiredMessages: found ${messages.length} messages to expire` ); @@ -38,7 +40,7 @@ await Promise.all(messageCleanup); inMemoryMessages.forEach(message => { - window.log.info('Message expired', { + window.SignalWindow.log.info('Message expired', { sentAt: message.get('sent_at'), }); @@ -50,23 +52,27 @@ } }); } catch (error) { - window.log.error( + window.SignalWindow.log.error( 'destroyExpiredMessages: Error deleting expired messages', error && error.stack ? error.stack : error ); } - window.log.info('destroyExpiredMessages: complete'); + window.SignalWindow.log.info('destroyExpiredMessages: complete'); checkExpiringMessages(); } let timeout; async function checkExpiringMessages() { - window.log.info('checkExpiringMessages: checking for expiring messages'); + window.SignalWindow.log.info( + 'checkExpiringMessages: checking for expiring messages' + ); const soonestExpiry = await window.Signal.Data.getSoonestMessageExpiry(); if (!soonestExpiry) { - window.log.info('checkExpiringMessages: found no messages to expire'); + window.SignalWindow.log.info( + 'checkExpiringMessages: found no messages to expire' + ); return; } @@ -82,7 +88,7 @@ wait = 2147483647; } - window.log.info( + window.SignalWindow.log.info( `checkExpiringMessages: next message expires ${new Date( soonestExpiry ).toISOString()}; waiting ${wait} ms before clearing` diff --git a/js/expiring_tap_to_view_messages.js b/js/expiring_tap_to_view_messages.js index efdb683083..3d9157d922 100644 --- a/js/expiring_tap_to_view_messages.js +++ b/js/expiring_tap_to_view_messages.js @@ -13,7 +13,9 @@ async function eraseTapToViewMessages() { try { - window.log.info('eraseTapToViewMessages: Loading messages...'); + window.SignalWindow.log.info( + 'eraseTapToViewMessages: Loading messages...' + ); const messages = await window.Signal.Data.getTapToViewMessagesNeedingErase( { MessageCollection: Whisper.MessageCollection, @@ -24,7 +26,7 @@ messages.map(async fromDB => { const message = MessageController.register(fromDB.id, fromDB); - window.log.info( + window.SignalWindow.log.info( 'eraseTapToViewMessages: message data erased', message.idForLogging() ); @@ -33,13 +35,13 @@ }) ); } catch (error) { - window.log.error( + window.SignalWindow.log.error( 'eraseTapToViewMessages: Error erasing messages', error && error.stack ? error.stack : error ); } - window.log.info('eraseTapToViewMessages: complete'); + window.SignalWindow.log.info('eraseTapToViewMessages: complete'); } let timeout; @@ -57,7 +59,7 @@ const nextCheck = receivedAt + THIRTY_DAYS; Whisper.TapToViewMessagesListener.nextCheck = nextCheck; - window.log.info( + window.SignalWindow.log.info( 'checkTapToViewMessages: next check at', new Date(nextCheck).toISOString() ); diff --git a/js/modules/debug.js b/js/modules/debug.js index 1e2fb5bb03..b5749bb3b3 100644 --- a/js/modules/debug.js +++ b/js/modules/debug.js @@ -2,7 +2,7 @@ // SPDX-License-Identifier: AGPL-3.0-only /* eslint-env node */ -/* global log, Signal */ +/* global Signal, window */ const fs = require('fs-extra'); const path = require('path'); @@ -58,7 +58,7 @@ exports.createConversation = async ({ await Promise.all( range(0, numMessages).map(async index => { await sleep(index * 100); - log.info(`Create message ${index + 1}`); + window.SignalWindow.log.info(`Create message ${index + 1}`); const message = await createRandomMessage({ conversationId }); return Signal.Data.saveMessage(message); }) @@ -108,7 +108,10 @@ const createRandomMessage = async ({ conversationId } = {}) => { }; const message = _createMessage({ commonProperties, conversationId, type }); - return Message.initializeSchemaVersion({ message, logger: log }); + return Message.initializeSchemaVersion({ + message, + logger: window.SignalWindow.log, + }); }; const _createMessage = ({ commonProperties, conversationId, type } = {}) => { diff --git a/js/modules/i18n.js b/js/modules/i18n.js index 975ffe9e5d..67093a8fbd 100644 --- a/js/modules/i18n.js +++ b/js/modules/i18n.js @@ -3,9 +3,6 @@ /* eslint-env node, browser */ -// eslint-disable-next-line no-console -const log = typeof window !== 'undefined' ? window.log : console; - exports.setup = (locale, messages) => { if (!locale) { throw new Error('i18n: locale parameter is required'); @@ -15,6 +12,10 @@ exports.setup = (locale, messages) => { } function getMessage(key, substitutions) { + // eslint-disable-next-line no-console + const log = + typeof window !== 'undefined' ? window.SignalWindow.log : console; + const entry = messages[key]; if (!entry) { log.error( diff --git a/js/modules/idle_detector.js b/js/modules/idle_detector.js index fd5eac4b18..b71ddb1eab 100644 --- a/js/modules/idle_detector.js +++ b/js/modules/idle_detector.js @@ -16,7 +16,7 @@ class IdleDetector extends EventEmitter { } start() { - window.log.info('Start idle detector'); + window.SignalWindow.log.info('Start idle detector'); this._scheduleNextCallback(); } @@ -25,7 +25,7 @@ class IdleDetector extends EventEmitter { return; } - window.log.info('Stop idle detector'); + window.SignalWindow.log.info('Stop idle detector'); this._clearScheduledCallbacks(); } diff --git a/js/modules/indexeddb.js b/js/modules/indexeddb.js index a057f3d4a8..699e3f941a 100644 --- a/js/modules/indexeddb.js +++ b/js/modules/indexeddb.js @@ -12,7 +12,9 @@ module.exports = { }; async function doesDatabaseExist() { - window.log.info('Checking for the existence of IndexedDB data...'); + window.SignalWindow.log.info( + 'Checking for the existence of IndexedDB data...' + ); return new Promise((resolve, reject) => { const { id } = Whisper.Database; const req = window.indexedDB.open(id); @@ -20,7 +22,7 @@ async function doesDatabaseExist() { let existed = true; setTimeout(() => { - window.log.warn( + window.SignalWindow.log.warn( 'doesDatabaseExist: Timed out attempting to check IndexedDB status' ); return resolve(false); @@ -41,6 +43,8 @@ async function doesDatabaseExist() { } function removeDatabase() { - window.log.info(`Deleting IndexedDB database '${Whisper.Database.id}'`); + window.SignalWindow.log.info( + `Deleting IndexedDB database '${Whisper.Database.id}'` + ); window.indexedDB.deleteDatabase(Whisper.Database.id); } diff --git a/js/modules/messages_data_migrator.js b/js/modules/messages_data_migrator.js index ff3e38d106..9f89e99e9d 100644 --- a/js/modules/messages_data_migrator.js +++ b/js/modules/messages_data_migrator.js @@ -45,7 +45,7 @@ exports.processNext = async ({ } ); } catch (error) { - window.log.error( + window.SignalWindow.log.error( 'processNext error:', error && error.stack ? error.stack : error ); diff --git a/js/modules/types/conversation.js b/js/modules/types/conversation.js index 8bf8150305..b222167e96 100644 --- a/js/modules/types/conversation.js +++ b/js/modules/types/conversation.js @@ -53,7 +53,7 @@ function buildAvatarUpdater({ field }) { const { hash, path } = avatar; const exists = await doesAttachmentExist(path); if (!exists) { - window.log.warn( + window.SignalWindow.log.warn( `Conversation.buildAvatarUpdater: attachment ${path} did not exist` ); } diff --git a/js/notifications.js b/js/notifications.js index 479b7bb886..1130267375 100644 --- a/js/notifications.js +++ b/js/notifications.js @@ -133,7 +133,7 @@ } if (status.type !== 'ok') { - window.log.info( + window.SignalWindow.log.info( `Not updating notifications; notification status is ${status.type}. ${ status.shouldClearNotifications ? 'Also clearing notifications' : '' }` @@ -145,7 +145,7 @@ return; } - window.log.info('Showing a notification'); + window.SignalWindow.log.info('Showing a notification'); let notificationTitle; let notificationMessage; @@ -191,7 +191,7 @@ } } else { if (userSetting !== SettingNames.NO_NAME_OR_MESSAGE) { - window.log.error( + window.SignalWindow.log.error( `Error: Unknown user notification setting: '${userSetting}'` ); } @@ -216,7 +216,7 @@ ); }, clear() { - window.log.info('Removing notification'); + window.SignalWindow.log.info('Removing notification'); this.notificationData = null; this.update(); }, diff --git a/js/reliable_trigger.js b/js/reliable_trigger.js index 4e3c79e8a0..3479c2705a 100644 --- a/js/reliable_trigger.js +++ b/js/reliable_trigger.js @@ -66,7 +66,7 @@ a2 = args[1], a3 = args[2]; const logError = function (error) { - window.log.error( + window.SignalWindow.log.error( 'Model caught error triggering', name, 'event:', diff --git a/js/rotate_signed_prekey_listener.js b/js/rotate_signed_prekey_listener.js index 4589cc5437..d61f57d9c1 100644 --- a/js/rotate_signed_prekey_listener.js +++ b/js/rotate_signed_prekey_listener.js @@ -21,13 +21,13 @@ } async function run() { - window.log.info('Rotating signed prekey...'); + window.SignalWindow.log.info('Rotating signed prekey...'); try { await getAccountManager().rotateSignedPreKey(); scheduleNextRotation(); setTimeoutForNextRun(); } catch (error) { - window.log.error( + window.SignalWindow.log.error( 'rotateSignedPrekey() failed. Trying again in five minutes' ); setTimeout(setTimeoutForNextRun, 5 * 60 * 1000); @@ -38,7 +38,7 @@ if (navigator.onLine) { run(); } else { - window.log.info( + window.SignalWindow.log.info( 'We are offline; keys will be rotated when we are next online' ); const listener = () => { @@ -53,7 +53,7 @@ const now = Date.now(); const time = storage.get('nextSignedKeyRotationTime', now); - window.log.info( + window.SignalWindow.log.info( 'Next signed key rotation scheduled for', new Date(time).toISOString() ); @@ -71,7 +71,9 @@ Whisper.RotateSignedPreKeyListener = { init(events, newVersion) { if (initComplete) { - window.log.info('Rotate signed prekey listener: Already initialized'); + window.SignalWindow.log.info( + 'Rotate signed prekey listener: Already initialized' + ); return; } initComplete = true; diff --git a/js/views/debug_log_view.js b/js/views/debug_log_view.js deleted file mode 100644 index b256db4091..0000000000 --- a/js/views/debug_log_view.js +++ /dev/null @@ -1,201 +0,0 @@ -// Copyright 2015-2021 Signal Messenger, LLC -// SPDX-License-Identifier: AGPL-3.0-only - -/* global i18n, Whisper, $ */ - -// eslint-disable-next-line func-names -(function () { - window.Whisper = window.Whisper || {}; - - // This enum-like object describes the load state of `DebugLogView`. It's designed to be - // unidirectional; `NotStarted` → `Started` → `LogsFetchedButNotInTextarea`, etc. - const LoadState = { - NotStarted: 0, - Started: 1, - LogsFetchedButNotInTextarea: 2, - PuttingLogsInTextarea: 3, - LogsInTextarea: 4, - }; - - Whisper.LoadingFullLogsToast = Whisper.ToastView.extend({ - render_attributes() { - return { toastMessage: i18n('loading') }; - }, - }); - - Whisper.LinkedCopiedToast = Whisper.ToastView.extend({ - render_attributes() { - return { toastMessage: i18n('debugLogLinkCopied') }; - }, - }); - - Whisper.DebugLogLinkView = Whisper.View.extend({ - template: () => $('#debug-log-link').html(), - initialize(options) { - this.url = options.url; - }, - events: { - 'click .copy': 'copy', - }, - render_attributes() { - return { - url: this.url, - reportIssue: i18n('reportIssue'), - debugLogCopy: i18n('debugLogCopy'), - debugLogCopyAlt: i18n('debugLogCopyAlt'), - }; - }, - copy(e) { - e.preventDefault(); - window.copyText(e.currentTarget.href); - Whisper.ToastView.show(Whisper.LinkedCopiedToast, document.body); - }, - }); - - /** - * The bulk of the logic in this view involves grabbing the logs from disk and putting - * them in a `