Commit Graph

260 Commits (c936859d0954061a86c133c6b80e96a2d7fbd9cd)

Author SHA1 Message Date
Scott Nonnenberg c02860af5c
Responding to pull request review feedback
- messages.getQuoteObjectUrl: early return
- backup.js: explaining variables for long if statement
- types/messages.js: Log if thumbnail has neither data nor path
- sendmessage.js:
  - remove extraneous logging
  - fix indentation
  - upload attachments and thumbnails in parallel
- preload: don't load fs for tests, just fse
- _conversation.scss: split two selectors into two lines, 0px -> 0
- backup_test.js: use fse.existsSync and comment twoSlashes regex
- network_tests_view_test.js: Comment duplicate assignment to window.getSocketStatus
7 years ago
Scott Nonnenberg a7d44d3344
Backup and end-to-end test! 7 years ago
Scott Nonnenberg 978ff0e2bb
Refactor: Use correct name for sanitized filename in backup.js 7 years ago
Scott Nonnenberg f1ff040842
Finish type definition for _mapQuotedAttachments 7 years ago
Scott Nonnenberg 9ad55c803f
Fix handling attachment thumbnails using thumbnail key 7 years ago
Scott Nonnenberg 054d3887a1
Quotes: The full pipeline into the database
1. MessageReceiver always pulls down thumbnails included in quotes
2. Message.upgradeSchema has a new schema that puts all thumbnails on
   disk just like happens with full attachments.
3. handleDataMessage pipes quote from dataMessage into the final message
   destined for the database
7 years ago
Scott Nonnenberg 21bf02c94d
Fixed examples in Quote.md, rough Android visuals 7 years ago
Daniel Gasienica d7b845326d ESLint auto-fix `link_text` 7 years ago
Daniel Gasienica 9d41b86162 Remove escaping from `linkText`
We leverage jQuery’s HTML escaping in `$.html(…)`.
7 years ago
Daniel Gasienica f04c65088b Fork `link-text` module 7 years ago
Daniel Gasienica 24f4ad53bc Use single quotes for identifiers 7 years ago
Daniel Gasienica 432a6ebd7f Redact file paths with escaped slashes 7 years ago
Daniel Gasienica a8a7525609 Redact stack traces with forward and backslashes 7 years ago
Daniel Gasienica b0da7d965e Redact URL encoded file paths in stack traces 7 years ago
Daniel Gasienica f2c9ccae90 Prefer `is.*` over Lodash `is*` functions 7 years ago
Daniel Gasienica 2ee78ec556 Prefer `path` over `Path` 7 years ago
Scott Nonnenberg c6c3b65bbc
Introduce React, TypeScript, TSLint and React-StyleGuidist (#2219)
Quite a bit of change here.

First, the basics:

- New dependencies were added: react, typescript, tslint, and react-styleguidist
- A new npm script: transpile. It uses typescript to process .tsx files in js/react, putting .js files next to the original file. It's part of the watch functionality of grunt dev as well as the default task run with just grunt (used to build the app prior to release). A lighter-weight to get watch behavior when just working on React components is to run yarn transpile --watch.
- yarn run clean-transpile will remove generated .js files


Style guide via react-styleguidist. Example site: https://react-styleguidist.js.org/examples/basic/

- Start with yarn styleguide
- Component.md files right next to the .tsx file
- jsdoc-style comments are picked up and added to the generated part of the styleguide - the overall summary and a table listing methods and properties of the component
- It has hot-reloading!
- It uses webpack, which means that our app now pulls in webpack though we don't use it to generate anything for the production app.
- I did a bunch of work to enable the use of Backbone views in this context, which will allow us to move smoothly from the old world to the new. First, add all the permutations in the old way, and then slowly start to re-render those same views with React.

A bit of dependency cleanup to enable use in React components:

- moment was moved from our Bower dependencies to our npm dependencies, so it can be used in React components not running in a browser window.
- i18n was moved into the new commonjs format, so it can be used in React components even if window is not available.

Lastly, a bit of Gruntfile cleanup:

- Removal of Chrome App-era modifications of background.js
- Make jshint/jscs watch more targeted, since more and more we'll be using other tools
7 years ago
Scott Nonnenberg 50d4dbaae7
Remove 'use strict' from i18n.js 7 years ago
Scott Nonnenberg 76be13552f
js/i18n.js -> js/modules/i18n.js 7 years ago
Daniel Gasienica 195e9b777c Rename `willHaveAttachmentsSavedOnFileSystemDuringUpgrade`
New name: `willAttachmentsGoToFileSystemOnUpgrade`
7 years ago
Daniel Gasienica 4c4443390a Rename `createImporter` to `createAttachmentDataWriter` 7 years ago
Daniel Gasienica 5ea1a305a6 Clarify error origin 7 years ago
Daniel Gasienica 9dcb64b53c Initialize schema version upon import 7 years ago
Daniel Gasienica cfad983d08 Consistently use `ciphertext` instead of `encrypted` 7 years ago
Daniel Gasienica a61c905146 Impliclity decrypt data if `key` is present 7 years ago
Daniel Gasienica 94c75762b5 Add `Message.createAttachmentLoader` 7 years ago
Daniel Gasienica 43ab320d31 Load attachments before writing them upon export 7 years ago
Daniel Gasienica 7eeabb5b1a Add precondition for `writeAttachment` 7 years ago
Daniel Gasienica 0faaf52b71 Import and upgrade messages upon save 7 years ago
Daniel Gasienica cf7355bd2f Rename `backupToDirectory` to `exportToDirectory`
For symmetry reasons.
7 years ago
Daniel Gasienica bf67254cc5 Add `Message.createImporter` 7 years ago
Daniel Gasienica efd673083d Rename `writeAttachmentData` to `writeNewAttachmentData` 7 years ago
Daniel Gasienica ce8fe0d345 Add `Signal.Startup` module 7 years ago
Daniel Gasienica 8474f3cf7f Use `create*` prefix to clarify curried functions 7 years ago
Daniel Gasienica 12cdeee7ec Rename `count` to `numMessagesPerBatch` 7 years ago
Daniel Gasienica 38ac9972e8 Improve termination condition 7 years ago
Daniel Gasienica 5b1a0c45df Replace `getAll` with cursor
This reduces the likelihood of IPC message size error.
7 years ago
Daniel Gasienica ed77378293 Fix bug in termination condition 7 years ago
Daniel Gasienica 052fb841f6 Allow database name override in migrations 7 years ago
Daniel Gasienica 1e04083813 Support database upgrades in `Database.open` 7 years ago
Daniel Gasienica f50ac1c99e Reduce excessive logging about database status 7 years ago
Daniel Gasienica 77b1f3c505 Replace startup with attachment background migration
Iterates through `Message::id` index.
7 years ago
Daniel Gasienica 057762806e Add support for attachment background migration without index 7 years ago
Daniel Gasienica 2e4893f4c1 Clarify implications of introducing new migrations 7 years ago
Daniel Gasienica 7413b787b6 Make `migrations` private 7 years ago
Daniel Gasienica b07c66eaa7 Generate attachments from local files
This ensures our benchmarking is closer to real-world usage, e.g. images, video,
etc. that are not compressible.
7 years ago
Daniel Gasienica 064a40544c Fix error message formatting 7 years ago
Daniel Gasienica 442f5d7295 Use `done` to match JavaScript iterators
See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators
7 years ago
Daniel Gasienica a4f0c5242f Document why batch size is one 7 years ago
Daniel Gasienica 805031ade8 Conditionally run post-attachment migrations
Introduce placeholder migrations for Backbone models so they never implicitly
run migrations whenever they are `fetch`ed. We prefer to run our migrations
explicitly upon app startup and then let Backbone models be (slightly) dumb(er)
models, without inadvertently triggering migrations.
7 years ago
Daniel Gasienica bfbeedab5c Temporarily disable post-attachment migration migrations 7 years ago
Daniel Gasienica d9be6a0f94 Destructure Lodash `require`s 7 years ago
Daniel Gasienica b7b6195cfc Extract IIFE into separate function 7 years ago
Daniel Gasienica 11f98474ba Capture how many messages we have to process 7 years ago
Daniel Gasienica 0fdc1140dd Add `Database.getCount` function 7 years ago
Daniel Gasienica 1f8556b049 Remove unused `createCollection` 7 years ago
Daniel Gasienica c67c2a858a Remove Backbone references for attachment migration
It has to run without any other migrations interfering.
7 years ago
Daniel Gasienica 0c40f35623 Document disadvantage of fetching messages without index 7 years ago
Daniel Gasienica d3c9de4712 Add debug module
Lets us generate large conversations with large attachments.
7 years ago
Daniel Gasienica 30037e5308 Reduce attachment migration batch size to 1
This prevents ‘Maximum IPC message size exceeded’ due to IDB `getAll` operation.

- https://github.com/zincbase/zincdb/issues/17
- https://cs.chromium.org/chromium/src/content/browser/indexed_db/indexed_db_database.cc?q=%22Maximum+IPC+message+size+exceeded%22&sq=package:chromium&l=1160
7 years ago
Daniel Gasienica 21147a20a0 Add `sleep` module 7 years ago
Daniel Gasienica 08f73b8420 Remove last processed index after attachment migration 7 years ago
Daniel Gasienica 696a144ab7 Add `settings.deleteItem` 7 years ago
Daniel Gasienica 5910f84af4 Remove outdated documentation 7 years ago
Daniel Gasienica efe3cd67fc Allow attachment migration run on higher database version 7 years ago
Daniel Gasienica 921c3dba7c Skip migrations that have already been applied 7 years ago
Daniel Gasienica 417511ffd2 Add `database.getVersion` 7 years ago
Daniel Gasienica c5c94bc3ab Extract `getMigrationVersions` 7 years ago
Daniel Gasienica 6aea36240d Rename `closeDatabase` to `closeDatabaseConnection` 7 years ago
Daniel Gasienica 016432826b Extract `database` and `settings` modules 7 years ago
Daniel Gasienica 5bea894abd Close database connection via Backbone IDB adapter 7 years ago
Daniel Gasienica f50e9ae364 Log closing connection of database 7 years ago
Daniel Gasienica 4ff8bc3357 Use `camelCase` for non-constructors 7 years ago
Daniel Gasienica 3720c3f3bb Improve log message 7 years ago
Daniel Gasienica ce5b450fdb Log `targetSchemaVersion` 7 years ago
Daniel Gasienica f7f24b5822 Log total number of processed messages 7 years ago
Daniel Gasienica eca930770c Remove hard-coded database connection settings 7 years ago
Daniel Gasienica 1df6dc8378 Abort processing if there are no more messages 7 years ago
Daniel Gasienica d5d0eabdfd Remove usage of `storage` module 7 years ago
Daniel Gasienica 8966e80284 Improve identifier names 7 years ago
Daniel Gasienica 3e2d575506 Document `MessageDataMigrator` module design 7 years ago
Daniel Gasienica 3c57dbfb56 Extract `NUM_MESSAGES_PER_BATCH` 7 years ago
Daniel Gasienica 85788d3c4a Match `items` storage format to Backbone adapter 7 years ago
Daniel Gasienica 7de7fcf561 Avoid `no-param-reassign` violation 7 years ago
Daniel Gasienica 070235b59b Implement `MessageDataMigrator.processAll`
Upgrades schema of all messags upon startup.
7 years ago
Daniel Gasienica 178a3cc262 Reduce work for verifying transaction completion 7 years ago
Daniel Gasienica b6e978f74c Implement `MessagesDataMigrator.processAll` 7 years ago
Daniel Gasienica 457bf7ab9d Add `createCollection` function 7 years ago
Daniel Gasienica 8ea257ad4d Use double quotes for identifiers in error messages 7 years ago
Daniel Gasienica 172616ca4f Add log message for dummy migration 18 7 years ago
Daniel Gasienica 579b01283e Replace `wrapDeferred` with `deferredToPromise` 7 years ago
Daniel Gasienica 40c40c800a Prefer `exports` 7 years ago
Daniel Gasienica da144edc56 Manually close database connection after migration 7 years ago
Daniel Gasienica 106ce21c49 Remove redundant log message 7 years ago
Daniel Gasienica fcd30cd919 Close database after migration
This is not 100% reliable as database connections are closed in a separate
thread according to the documentation:
- https://developer.mozilla.org/en-US/docs/Web/API/IDBDatabase/close
- https://stackoverflow.com/a/18639298
- 80c7a06d5c/backbone-indexeddb.js (L558-L565)
7 years ago
Daniel Gasienica c765422fa1 Extract `deferredToPromise` 7 years ago
Daniel Gasienica e2f1339ab9 Explicitly run post-attachment migrations 7 years ago
Daniel Gasienica d7c8d33edb Extract `runMigrations` 7 years ago
Daniel Gasienica d16178638e Split database migrations into pre- and post-attachment migration
- Run light-weight migrations before attachment migration.
- Run regular migrations after attachments have been moved to disk.
7 years ago
Daniel Gasienica 90de9d85a3 Remove type annotation 7 years ago
Daniel Gasienica 4c10fcfa17 Reduce threshold until optimization appears to 1s 7 years ago
Daniel Gasienica add19aa732 Add initialization view 7 years ago
Daniel Gasienica 9b112489cd Upgrade 2 messages every 30 seconds
This results in 4 messages per minute or 240 messages per hour.
7 years ago
Daniel Gasienica 7c2fde4433 Add `Signal.Workflow` namespace 7 years ago
Daniel Gasienica 4a7cc22de3 🎨 Use `window.requestIdleCallback` 7 years ago
Daniel Gasienica 4651cbc2eb Improve ``Message.upgradeSchema` preconditions 7 years ago
Daniel Gasienica ca28f3030b Add `MessageMigration` module 7 years ago
Daniel Gasienica 8e762797c0 Remove attachment validation
Turns out `fileName` is optional and maybe even `contentType`. We should revisit
this at a later point in time.
7 years ago
Daniel Gasienica 09ee2d4ea2 Switch to using `requestIdleCallback`
Example:
https://developer.mozilla.org/en-US/docs/Web/API/Background_Tasks_API#Example
7 years ago
Daniel Gasienica d13668544d Rename `IdleListener` to `IdleDetector` 7 years ago
Daniel Gasienica 3140e4d66d Implement basic `IdleListener` 7 years ago
Daniel Gasienica 867f73b80a Use double quotes for identifiers in error messages 7 years ago
Daniel Gasienica 70cdd2b350 Add `stringToArrayBuffer` utility
This way we can avoid an extra dependency.
7 years ago
Daniel Gasienica 2ad0fd7db6 Use Lodash `omit` instead of `delete` 7 years ago
Daniel Gasienica 279b3f81c7 Add `Attachment.deleteData` 7 years ago
Daniel Gasienica 9a540d6d18 Load attachment data before sending message 7 years ago
Daniel Gasienica 6355c54114 Return relative path from `writeAttachmentData`
This will make our app more robust to changes in location on the file system.
7 years ago
Daniel Gasienica 2cd3d5ac16 Add `Message` schema version 3 7 years ago
Daniel Gasienica aa82a2a5fb Add `context` to `Message.upgradeSchema`
Allows us to pass in Electron/Node.js specific functions. This allows better
unit testing in Mocha where we don’t have access to Electron APIs.
7 years ago
Daniel Gasienica ebe2a769c9 Add `Attachment.migrateDataToFileSystem` 7 years ago
Scott Nonnenberg cea42bde7d
Encryption support for backup and restore
Also moved to the _ prefix in backup.js for all private methods exported
for testing.
7 years ago
Scott Nonnenberg 6d8f4b7b6e
Backup: zipped messages.json, flat attachments dir
Backup creates, in a target directory:
  - An attachments folder, with all attachments, each named for their
    parent message's id - a GUID. If there is more than one attachment
    in a given message,  each attachment beyond the first will end with
    '-N', zero-indexed.
  - A file named messages.zip. It contains exactly what went to disk in
    the original export code, but zipped up.

Export is now only 'light,' and in this new messages.zip format.

Import supports both the new format and the old format. If the target
directory has a messages.zip file, we'll treat it as the new format.

Next up: Encrypting attachments and the messages.zip!
7 years ago
Scott Nonnenberg 153a22f46b
Exclude unnecessary data in export: profiles, replayable errors 7 years ago
Scott Nonnenberg c0c758d459
Backup: All exports are now 'light' exports 7 years ago
Scott Nonnenberg e583434366
Refactor: Move Backup under window.Signal 7 years ago
Daniel Gasienica c88381efe3 Use `async` / `await` to improve readability 7 years ago
Daniel Gasienica 2642844c27 Rewrite migration 17 without `idb`
We ran into issues when doing async operations inside of an IndexedDB
`onupgradeneeded` handler. The errors were ‘The transaction is not active’ or
‘Transaction has finished’. The following documentation confirmed that
transactions are committed/terminated when control returns to the event loop:

Spec
- https://www.w3.org/TR/IndexedDB/#transaction-lifetime-concept
- https://www.w3.org/TR/IndexedDB/#upgrade-transaction-construct

Stack Overflow
- https://stackoverflow.com/a/11059085
- https://stackoverflow.com/a/27338944

Since the initial database migration is so critical, I decided to avoid `idb`
with promise support for IndexedDB for now, but will reconsider using it for
other tasks in the future to improve readability of IndexedDB code.
7 years ago
Daniel Gasienica a619d48fac Update schema version history 7 years ago
Daniel Gasienica 0e20e8e2ea Use `Errors.toLogFormat` 7 years ago
Daniel Gasienica a5edbf8328 Initialize schema as first step in `upgradeSchema` 7 years ago
Daniel Gasienica 5d927b73e6 Use `while` loop for IDB cursor iteration
Previously, I messily combined promises and callbacks because I thought we
were affected by the microtask issue:
https://github.com/gasi/idb#iteratecursor--iteratekeycursor

ESLint’s `more/no-then` encouraged me to revisit this and it works as expected.
7 years ago
Daniel Gasienica 182e6ffe10 Add version 17 migration 7 years ago
Daniel Gasienica 752c8f97e6 🎨 Format ternaries 7 years ago
Daniel Gasienica 8dfaa5619f Prefix private functions with underscore 7 years ago
Daniel Gasienica ed336d31d7 Move schema versioning from `Attachment` to `Message` 7 years ago
Daniel Gasienica b9e9f5e19a 🎨 `withInheritedSchemaVersion` to `inheritSchemaVersion` 7 years ago
Daniel Gasienica df693ade7c Allow `Attachment.fileName` to be `null` 7 years ago
Daniel Gasienica c27746b79e Add `Message.withInheritedSchemaVersion` 7 years ago
Daniel Gasienica e9e46464c2 Add `SchemaVersion` type 7 years ago
Daniel Gasienica add4b11df3 Skip invalid attachments and make function sync 7 years ago
Daniel Gasienica 3dfc823716 Add `Attachment.removeSchemaVersion` 7 years ago
Scott Nonnenberg 26c273618a
Refactor: db tasks to database.js, log delete to modules/logs.js 7 years ago
Daniel Gasienica 43b47fd349 Avoid `ensure-error` for privacy reasons
Example:

```
> node
> const nonError = {foo: 'i-am-private'};
undefined

// before
> util.inspect(nonError);
'{ foo: \'i-am-private\' }'

// after
> nonError.toString()
'[object Object]'
>
```
7 years ago
Daniel Gasienica ea07915e6b Escape special characters in file path 7 years ago
Daniel Gasienica 44b81f68dd Remove privacy redaction from `Errors.toLogFormat` 7 years ago
Daniel Gasienica 49e0850fb2 Extract `Privacy` module
Centralizes how we redact sensitive information.
7 years ago
Daniel Gasienica 0e2f8a8a06 Extract `Errors.redactSensitivePaths` 7 years ago
Daniel Gasienica 3dffdc3f0b Rename `Errors` to `GlobalErrors` for clarity 7 years ago
Daniel Gasienica 2575196617 Extract `Errors.addGlobalHandler` procedure 7 years ago
Daniel Gasienica be3e4d86c2 Add `Errors.toLogFormat`
Allows errors to be formatted and sanitized for logging. Removes sensitive paths
such as the app root directory.

Ideally, this module would be called singular `Error` but that is already a
global name. Using `Errors` plural is  similar to Java convention for utilities
such as `Arrays`, `Collections`, `Files`, etc. See:
https://stackoverflow.com/a/11673838
7 years ago