Commit Graph

2129 Commits

Author SHA1 Message Date
Daniel Gasienica cd985aa700 Document type signature of FileInputView::readFile 2018-02-15 15:16:58 -05:00
Daniel Gasienica d70d70e52c Move attachment processing closer to sending
This helps ensure processing happens uniformly, regardless of which code paths
are taken to send an attachment.
2018-02-15 15:16:58 -05:00
Daniel Gasienica 532ac3e273 Process attachment before it’s sent
Picked this place since it already had various async steps, similar to
`onMessageReceived` for the incoming `Attachment.process`.

Could we try have this live closer to where we store it in IndexedDB, e.g.
`Conversation::sendMessage`?
2018-02-15 15:16:58 -05:00
Daniel Gasienica a4582ae2fb Refactor getFile and getFiles
Lint them using ESLint.
2018-02-15 15:16:58 -05:00
Daniel Gasienica 07e9114e65 Document incoming and outgoing attachments fields
Note how outgoing message attachments only have 4 fields. This presumably means
the others are not used in our code and could be discarded for simplicity.
2018-02-15 15:16:58 -05:00
Daniel Gasienica fdc3ef289d Highlight that dataURLToBlob is synchronous 2018-02-15 15:16:58 -05:00
Daniel Gasienica e56101e229 Replace custom with blob-util functions
IMPORTANT: All of them are async so we need to use `await`, otherwise we get
strange or silent errors.
2018-02-15 15:16:58 -05:00
Daniel Gasienica f95150f6a9 Revert "Replace custom functions with blob-util"
This reverts commit 8a81e9c01bfe80c0e1bf76737092206c06949512.
2018-02-15 15:16:58 -05:00
Daniel Gasienica 33860d93f3 Revert "Replace blueimp-canvas-to-blob with blob-util"
This reverts commit 31b3e853e4afc78fe80995921aa4152d9f6e4783.
2018-02-15 15:16:58 -05:00
Daniel Gasienica 7a0ba6fed6 Replace blueimp-canvas-to-blob with blob-util 2018-02-15 15:16:58 -05:00
Daniel Gasienica 47a5f2bfd8 Replace custom functions with blob-util 2018-02-15 15:16:58 -05:00
Daniel Gasienica 9ac26be1bd Document why we drop original image data during auto-orient 2018-02-15 15:16:58 -05:00
Daniel Gasienica 4136d6c382 Extract DEFAULT_JPEG_QUALITY 2018-02-15 15:16:58 -05:00
Daniel Gasienica 4a7156327e Drop support for invalid image/jpg MIME type 2018-02-15 15:15:00 -05:00
Daniel Gasienica 69fe96581f Document window.onInvalidStateError global 2018-02-15 15:15:00 -05:00
Daniel Gasienica a48ba1c774 Selectively run ESLint on js/background.js
Enabling ESLint on a per function basis allows us to incrementally improve the codebase
without requiring large and potentially risky refactorings.
2018-02-15 15:15:00 -05:00
Daniel Gasienica e6d1cf826b Move async attachment processing to onMessageReceived
We previously processed attachments in `handleDataMessage` which is mostly a synchronous
function, except for the saving of the model. Moving the processing into the already async
`onMessageReceived` improves code clarity.
2018-02-15 15:15:00 -05:00
Daniel Gasienica e0cc3d8fab Implement attachment process version
Instead of keeping track of last normalization (processing) date, we now keep track of
an internal processing version that will help us understand what kind of processing has
already been completed for a given attachment. This will let us retroactively upgrade
existing attachments.

As we add more processing steps, we can build a processing pipeline that can convert any
attachment processing version into a higher one, e.g. 4 -> 5 -> 6 -> 7.
2018-02-15 15:15:00 -05:00
Daniel Gasienica ebcb70258a Whitelist browser environment for ESLint 2018-02-15 15:14:59 -05:00
Daniel Gasienica 3eaace6f3a Use MIME module 2018-02-15 15:14:59 -05:00
Daniel Gasienica ba2cf7770e 🎨 Fix lint errors 2018-02-15 15:14:59 -05:00
Daniel Gasienica 65acc86e85 Add ES2015+ files to JSHint ignored list 2018-02-15 15:14:59 -05:00
Daniel Gasienica 8b6494ae6c Document potentially unexpected autoScale behavior 2018-02-15 15:14:59 -05:00
Daniel Gasienica 213400e4b2 Add MIME type module 2018-02-15 15:14:59 -05:00
Daniel Gasienica 37a726e4fb Return proper Error from blobArrayToBuffer 2018-02-15 15:14:59 -05:00
Daniel Gasienica 164752db56 🎨 Fix ESLint errors 2018-02-15 15:14:59 -05:00
Daniel Gasienica d498dd79a0 Update Attachment type field definitions 2018-02-15 15:14:59 -05:00
Daniel Gasienica 141155a153 Move blueimp-canvas-to-blob from Bower to npm 2018-02-15 15:14:59 -05:00
Daniel Gasienica 7ccb833e5d 🎨 Clarify data flow 2018-02-15 15:14:59 -05:00
Daniel Gasienica e7da41591f Use blobUrl for consistency 2018-02-15 15:14:59 -05:00
Daniel Gasienica 523a80eefe Remove just-in-time image auto-orient for lightbox
We can bring this back if our users would like auto-orient for old attachments.
2018-02-15 15:14:59 -05:00
Daniel Gasienica 0739feae9c Remove just-in-time auto-orient of message attachments
We can bring this back if our users would like auto-orient for old attachments. But better
yet, we might implement this as database migration.
2018-02-15 15:14:59 -05:00
Daniel Gasienica ed43c66f92 Auto-orient JPEG attachments upon receipt 2018-02-15 15:14:59 -05:00
Daniel Gasienica 9638fbc987 Use contentType from model 2018-02-15 15:14:59 -05:00
Daniel Gasienica 032c0ced46 Return Error object for autoOrientImage failures 2018-02-15 15:14:59 -05:00
Daniel Gasienica ff04bad851 Add options for autoOrientImage output type / quality 2018-02-15 15:14:59 -05:00
Daniel Gasienica 87745b5586 Add Attachment type
Defines various functions on attachments, e.g. normalization (auto-orient JPEGs, etc.)
2018-02-15 15:14:59 -05:00
Daniel Gasienica 59974db5a5 Improve readability 2018-02-15 15:14:59 -05:00
Daniel Gasienica b5ba96f1e6 Use snake_case for module names
Prevents problems across case-sensitive and case-insensitive file systems.

We can work around this in the future using a lint rule such as
`eslint-plugin-require-path-exists`.
See discussion:
https://github.com/signalapp/Signal-Desktop/pull/2040#discussion_r167365931
2018-02-15 15:14:59 -05:00
Daniel Gasienica 4822f49f22 Auto-orient images in lightbox view 2018-02-15 15:14:59 -05:00
Daniel Gasienica 7317110809 Document magic number for escape key 2018-02-15 15:14:59 -05:00
Daniel Gasienica c790d07389 Make second View argument an options object 2018-02-15 15:14:59 -05:00
Daniel Gasienica d07433e3cf Make autoOrientImage module standalone 2018-02-15 15:14:59 -05:00
Daniel Gasienica c285bf5e33 Replace loadImage with autoOrientImage 2018-02-15 15:14:59 -05:00
Daniel Gasienica 4431854923 Add autoOrientImage module
This module exposes `loadImage` with a `Promise` based interface and pre-
populates `orientation: true` option to auto-orient input. Returns data URL
as string.

The module uses a named export as refactoring references of modules with
`default` (`module.exports`) export references can be error-prone.
See: https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html
2018-02-15 15:14:59 -05:00
Daniel Gasienica c77063afc6 Auto-orient preview images
See: #998
2018-02-15 15:14:59 -05:00
Daniel Gasienica 06dba5eb8f TODO: Use native Canvas::toBlob
One challenge is that `Canvas::toBlob` is async whereas `dataURLtoBlob` is sync.
2018-02-15 15:14:59 -05:00
Daniel Gasienica b15c304a31 Make null check strict
Appeases JSHint. ESLint has a nice `smart` option for `eqeqeq` rule:
https://eslint.org/docs/rules/eqeqeq#smart
2018-02-15 15:14:59 -05:00
Daniel Gasienica ea70b92d9b Use Canvas::toDataURL to preserve ImageView logic
This way, all the other code paths remain untouched in case we want to remove
the auto-orient code once Chrome supports the `image-orientation` CSS property.

See:
- #998
- https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation
2018-02-15 15:14:59 -05:00
Daniel Gasienica 62fd744f9f Use CSS to constrain auto-oriented images 2018-02-15 15:14:59 -05:00