When typing in an existing phone number into the search, clicking on it even
though there exists an existing contact will reinitialize that contact’s
database entry. This reinitialization clears that contact’s conversation’s name,
unread count, etc.
This change ensures we always reuse existing conversations using
`ConversationController.getOrCreateAndWait` when starting new conversations in
the search view.
When searching for an existing conversation using a phone number, it’s possible
to click on ‘Start conversation…’ and have that new dummy entry overwrite the
existing conversation.
This change ensures we are always showing a dummy conversation model that is not
part of the conversation collection. Adding it is always idempotent as it goes
through `getOrCreateAndWait`.
Class: `ConversationController`.
This function should not be used in application code as it creates potentially
invalid `Conversation` instances in our global conversation collection. We keep
making it available for testing purposes.
- We first show a localized loading message.
- If initialization takes longer than a certain threshold, we show a different
‘optimization’ message.
- If initialization is below the threshold the message change is canceled right
before the regular loading screen.
Let’s make it clear that this is where we initialize our namespaces to avoid
proliferation of various initialization points now that we support CommonJS.
In order to avoid incurring long startup times, we migrate message schema (data) in the background using `window.requestIdleCallback` API. The migration moves attachment data from IndexedDB to disk and reduces load on our database which may cause data loss (#1589).
On my development profile, this migration reduced the IndexedDB directory from 33.4MB to 4.7MB.
- [x] Generate random file names.
- [x] Generate random file paths that prevent too many files per folder using
fan-out.
- [x] Create attachment directory in user data folder.
- [x] Investigate operating system file indexing on:
- [x] Windows: Confirmed that `AppData` is not indexed by default.
- [x] macOS: Confirmed that `~/Library` files are not indexed by default.
Searching system files using Spotlight requires multi-step opt-in:
https://lifehacker.com/5711409/how-to-search-for-hidden-packaged-and-system-files-in-os-x.
More info https://apple.stackexchange.com/a/92785.
Added `.noindex` suffix to `attachments` folder.
- [x] Linux: n/a
- [x] Save incoming attachment files to disk
- [x] On received
- [x] On sync
- [x] Save outgoing attachments files to disk before sending
- [x] Display attachments either from disk or memory in attachment view.
Be robust to multiple render passes.
- [x] Test that missing attachment on disk doesn’t break app.
Behavior: Message is displayed without attachment.
- [x] Delete attachment files when message is deleted.
Relates to #1589.