Commit graph

327 commits

Author SHA1 Message Date
Jackie Luo
6e111c073a fix(message-ids): Use correct hashing for headers 2016-12-08 17:55:39 -08:00
Jackie Luo
fae855f0fe feat(message-ids): Hash message IDs and replace in draft before sending 2016-12-08 17:48:34 -08:00
Evan Morikawa
947eb99b8d [local-sync] fix builds. Routes with trailing slash and main extension 2016-12-08 14:17:42 -08:00
Jackie Luo
7a763b604e feat(tracking): Add routes for open and link tracking 2016-12-08 13:38:29 -08:00
Juan Tejada
1ba56c5c05 [local-sync] Fix lint error 2016-12-08 10:28:29 -08:00
Evan Morikawa
2f786a8e91 [local-sync] fix delta sync not getting threads with updated labels 2016-12-07 17:47:49 -08:00
Evan Morikawa
d161a30a34 [local-sync] Add global dbs and cleanup orphan messages 2016-12-07 16:39:01 -08:00
Juan Tejada
878735f52e [local-sync] Add todos 2016-12-07 16:16:45 -08:00
Juan Tejada
a185a8a5fe [local-sync] Fix file/contact creation
We were getting sql unique constraint violation errors for ids because
we were attempting to create objects with the same id within the same
transaction.

This commit ensures that only attempt to write a contact with the same
id once, and that we check for all exsiting contacts before hand.

For file, we ensure that we don't attempt to write 2 files with the same
id more than once
2016-12-07 14:48:57 -08:00
Halla Moore
56f8d41b8c [local-sync] feat(send): Add support for attachments
Also move some helper function logic onto the Message model
2016-12-07 14:16:36 -08:00
Juan Tejada
8307976df8 [local-sync]: Fix label/folder id creation
We were using the stripped version of label/folder names for the id
hash, e.g. [Gmail]/Drafts would be Drafts.
However, we can't do this because it might collide with other names. e.g. if the
user created a Drafts label, it would end up colliding with [Gmail]/Drafts

Minor lint fix
2016-12-07 13:39:41 -08:00
Christine Spang
a23c68092e [local-sync] Add specs for message parsing
Summary:
This commit also fixes snippets for HTML-only messages to strip out HTML
tags, and makes us preserve whitespace for plaintext emails by
displaying them in <pre class="nylas-plaintext"> tags, and makes us log
messages that fail to parse at all to a tempdir.

The only issue I found with using <pre> tags for plaintext email was
that some lines may trigger scrolling, so there is an associated commit
(D3484) that changes the CSS for <pre class="nylas-plaintext"> to wrap
lines.

In the future, we can add regression tests to this test suite whenever
we fix parsing bugs.

Test Plan: unit tests included

Reviewers: bengotow

Reviewed By: bengotow

Differential Revision: https://phab.nylas.com/D3483
2016-12-07 07:25:28 -08:00
Ben Gotow
c3bd3dc297 [local-sync] Don’t update contacts if name is the same 2016-12-06 17:51:12 -08:00
Evan Morikawa
83ef47d049 [*] package.json updates from lerna 2016-12-06 16:03:31 -08:00
Evan Morikawa
8cbda7505a [*] fix auth 2016-12-06 16:03:31 -08:00
Evan Morikawa
2cbb90bb3b [*] DRY Auth 2016-12-06 16:03:31 -08:00
Evan Morikawa
896f981408 [isomorphic-core] extract AuthHelpers to DRY 2016-12-06 16:03:31 -08:00
Juan Tejada
7468e8123e [local-sync] Update DeleteSentMessage task for ordering 2016-12-06 15:54:45 -08:00
Juan Tejada
fda7fe18cc [local-sync] Ensure order correct order when running syncback requests
When running syncback requests, if a task is meant to change the UID of
a message (e.g. move it to a new folder), that task should be run after
other tasks that don't affect the UID. Otherwise, when trying to run the
other tasks, they would reference a UID that is no longer valid.

This commit will make sure that we run any tasks that will change message uids last,
/and/ make sure that we don't run more than 1 task that will affect the uids of
the same messages in a row (i.e. without running a sync loop in between)
2016-12-06 15:45:34 -08:00
Halla Moore
e785d73bdc [local-sync, iso-core] feat(send): add finishing touches to gmail multi-send
Delete the sent messages that gmail automatically creates and save our
generic form of the draft as a sent message.
2016-12-06 11:37:47 -08:00
Juan Tejada
1a24840062 [local-sync] Correctly sync folders and labels
This commit will correctly keep track of folder and label ids when
creating them from N1.

Previously, when we sent the request to create a folder or label to our api,
we would immediately get back a serverId because it was created optimistically
in the back end— given that K2 is strictly non-optimistic, we won’t have a serverId
until some undetermined time in the future, and we need to somehow reference
the object that /was/ optimistically created in N1 to update the ui when
we do get the server id.

Since we can deterministically generate ids for folders and labels,
we "guess" what its going to be, and include it in the props of the syncback request
returned to N1. This is the simplest solution to get thing working
correctly right now, but we’ll need to revisit this in the future for
other types of objects (drafts, contacts, events), and revisit how we
will manage optimistic updates in N1 when we merge the 2 codebases
with K2 (given that K2 was designed to be non-optimisitc).
2016-12-05 18:56:36 -08:00
Ben Gotow
aed1d59916 [local-sync] fix(folder-list): Support children when parent has no attribs 2016-12-05 16:20:17 -08:00
Ben Gotow
1e3b346c94 [local-sync] feat(specs): Add basic tests for folder sync 2016-12-05 16:07:49 -08:00
Karim Hamidou
04b1763965 [fix] Fix transaction creation for contacts
Summary:
Fixes T7283. We weren't creating deltas for contacts because we were inserting contacts using `UPSERT`, which requires us to add another sequelize hook.  Unfortunately, support for this hook is only available on sequelize 4.x.

I didn't want to upgrade our sequelize version right now and cause of bunch of mysterious failures, so I've simply changed the `UPSERT` to be either an `INSERT`or `UPDATE`. We didn't really need it anyway.

Test Plan: Checked that N1 was receiving contact deltas.

Reviewers: bengotow

Reviewed By: bengotow

Maniphest Tasks: T7283

Differential Revision: https://phab.nylas.com/D3481
2016-12-05 15:37:17 -08:00
Ben Gotow
269d61171a [local-sync] fix(specs): New specs for threading 2016-12-05 15:00:37 -08:00
Halla Moore
63032a2449 [local-sync] Fix(send): change some validation fields for multi-send 2016-12-05 12:55:56 -08:00
Ben Gotow
30c8bedd7a [local-sync] fix(specs): run npm test in local-sync dir 2016-12-05 12:16:53 -08:00
Ben Gotow
017e22c88d [*] Allow zero elements in the replyTo field 2016-12-05 09:57:47 -08:00
Halla Moore
6a51036e48 [local-sync, iso-core, cloud-core] feat(send): add multi-send support
Also renames JSONType() -> buildJSONColumnOptions() and
JSONARRAYType() -> buildJSONARRAYColumnOptions() to prevent passing
those return values in as just the type value instead of the entire
options object.
2016-12-02 15:20:31 -08:00
Evan Morikawa
2ba326dfc6 [local-sync] only enable logging in dev mode of N1 2016-12-02 17:34:05 -05:00
Christine Spang
9752eea9f7 [local-sync] Set thread IDs to the ID of a message in the thread
Since message IDs are now static but there's no good way to generate
static thread IDs while syncing an account from newest message first,
we give threads the ID of any message on that thread and, when setting
metadata, look up the local thread ID by first going through the
message table.
2016-12-02 14:13:47 -08:00
Evan Morikawa
b06566d8bd [local-sync] make syncbackRequest objects N1-ready 2016-12-02 16:14:42 -05:00
Juan Tejada
b36f61812d [local-sync]: Don't create or sync \NonExistent or \NoSelect folders 2016-12-02 12:14:09 -08:00
Juan Tejada
5ac3fe9ea8 [local-sync] Fix starred role on folders 2016-12-02 12:07:21 -08:00
Ben Gotow
7712269402 [*] fix(deltas): Cloud-API not filtering deltas at all, refactor a few things
- Don’t need functions in delta.js which must be called to return promsies. Fun of promsies is that you don’t need to care when they’re built to attach a .then.

- Make boundary between route handler and delta stream builder more explicit, don’t do query parsing in helpers, always reply from handler.

- Remove pushJSON extension to outputStream which never actually received JSON.

- Remove `takeUntil` - disposing of the downstream observable should dispose of all the merged/upstream observables

- Rename inflate => stringify since the returned value is a string not an object.

- Remove support for delta streams with no cursors. Don’t think this was supposed to be a feature.

- Add accountId to Transaction models

- Make database hooks shared in isomorphic core
2016-12-01 18:41:46 -08:00
Karim Hamidou
15cfe2cec0 Strip the '[Gmail]/' prefix from folder names.
Summary:
T7253 has two related parts:
1. Stripping the '[Gmail]/' prefix from any canonical Gmail folders
2. Handling nested IMAP folders.

This diff fixes 1. Changes for 2. are forthcoming.

Test Plan: Tested manually. Checked that the part was stripped from the N1 folder list.

Reviewers: juan

Reviewed By: juan

Differential Revision: https://phab.nylas.com/D3475
2016-12-01 16:49:09 -08:00
Juan Tejada
d650be5429 [local-sync] Refactor tasks and /actually/ fix moving between Gmail folders
Moving to between gmail folders (all, spam, trash) or moving to inbox,
involves changing labels /and/ folders, simultaneously. For this I added
a task to perform both operations, and apply labels first before
attempting to move the folder
2016-12-01 16:37:49 -08:00
Ben Gotow
4b4ab726e2 [💄] fix eslint issues before they get overwhelming 2016-12-01 15:37:48 -08:00
Karim Hamidou
aa49f85980 Fix bug where we wouldn't create an id for file parts. 2016-12-01 15:30:01 -08:00
Juan Tejada
2d932dd090 [*] Generate persistent id for Accounts based on email+settings
This also ensures that we can use the accountId as part of the ids for
other models, like labels and folders

Before this commit, labels and folders with the same name for different
accounts would have the same id, screwing things up in n1
2016-12-01 14:51:33 -08:00
Ben Gotow
47d8614ed7 [local-sync] Ship first sync metrics to honeycomb 2016-12-01 14:23:52 -08:00
Juan Tejada
ce27b0db2a [local-sync] Fix setlabels task
Make sure we /remove/ the labels when we get an empty set of label ids
2016-12-01 14:03:19 -08:00
Juan Tejada
b43be69cd3 [local-sync] Give better name to thread folders task 2016-12-01 13:30:47 -08:00
Juan Tejada
8939364dc3 [local-sync]: Add distinct ids to folders and labels 2016-12-01 11:57:29 -08:00
Karim Hamidou
47e0683cac First step to getting persistent id in K2
Summary:
This diff adds persistent unique ids for messages and contacts. For messages, we just take a hash of the headers. For contacts, we hash the contact's email address.

This diff bundles a couple of tiny fixes too, like always trying to restart an account's sync, even after an exception.

Note that since there's no reliable way to have persistent ids for threads, we'll have to change our code to use message ids instead. Alas, that's a story for another (massive) diff.

Test Plan: Tested manually.

Reviewers: bengotow

Reviewed By: bengotow

Differential Revision: https://phab.nylas.com/D3468
2016-12-01 11:15:13 -08:00
Ben Gotow
3d79f9b8be [local-sync] Run message processor for one message at a time
This avoids issues that arise when we process two messages on the same thread concurrently!
2016-11-30 17:26:23 -08:00
Ben Gotow
94722f27ab [local-sync] Fix “Add INBOX label” issue 2016-11-30 16:26:53 -08:00
Ben Gotow
bf9db2738c [local-sync] Fix ingestion of flags and labels 2016-11-30 16:26:53 -08:00
Ben Gotow
935d8cf141 [local-sync] Fix transaction log to only ignore syncState 2016-11-30 16:25:28 -08:00
Ben Gotow
2476cae297 [local-sync] Sync a bit faster for testing 2016-11-30 16:25:28 -08:00
Ben Gotow
1e01878e5a fix(sync): Fix attribute updates applying to threads 2016-11-30 13:55:49 -08:00
Evan Morikawa
a36b1e1f28 [*] add delta endpoints and DRY deltaStreamBuilder
[cloud-core] add objectType to Metadata

[*] binding fixes to delta stream
2016-11-30 13:41:09 -05:00
Juan Tejada
a37b90a209 [local-sync] Remove unecessary db queries in detect-thread 2016-11-30 10:17:59 -08:00
Ben Gotow
ece519553f fix(sync): Issue with CONDSTORE args not passed to fetch 2016-11-29 18:02:25 -08:00
Ben Gotow
82f505b659 refactor(sync-worker): Convert IMAP operations to async/await 2016-11-29 17:04:01 -08:00
Ben Gotow
fb9d770cc6 refactor(sync-worker) async/await for Karim 2016-11-29 16:20:18 -08:00
Ben Gotow
0c79ebb86a [local-sync] Synchronize K2 accounts with N1 accounts 2016-11-29 16:07:33 -08:00
Karim Hamidou
0879b6390e Make db reset synchronous. 2016-11-29 15:13:42 -08:00
Juan Tejada
20be7cc513 [local-sync] properly save folders when detecting thread 2016-11-29 15:04:45 -08:00
Karim Hamidou
ac818f30fe Add a shortcut to restart the sync for an account from scratch. 2016-11-29 14:59:37 -08:00
Ben Gotow
48fff4f4e1 fix(dashboard): Remove sync policy 2016-11-29 14:58:52 -08:00
Juan Tejada
b459076415 [local-sync] minor fix 2016-11-29 12:52:36 -08:00
Juan Tejada
b7b0808689 [local-sync]: Load all db models 2016-11-29 12:38:49 -08:00
Juan Tejada
a9be3bb3ed [local-sync]: Refactor message ingestion to write new messages only once
This will only generate 1 delta per new message instead of 2
Adds a MessageFactory to create messages from imapmessage objects, and
unifies and cleans up that logic
Also modified the message-processor to be more suited for local sync,
made emphasis that it's only for processing new messages, and got rid of
the while "pipeline" concept

- TODO message-processor specs are broken
2016-11-29 11:24:27 -08:00
Evan Morikawa
fc24ffea63 [isomorphic-core]: move Transaction model to isomorphic-core 2016-11-29 13:57:19 -05:00
Ben Gotow
f804c53522 [dashboard] Put dashboard into work window 2016-11-28 18:02:42 -08:00
Halla Moore
10f62f6b5a [local-sync, iso-core] feat(send): Support basic sending for gmail accounts 2016-11-28 14:46:31 -08:00
Ben Gotow
217ba1e020 [sync]: Sync again immediately if more emails remain 2016-11-28 12:00:57 -08:00
Juan Tejada
f9b6e63958 [local-sync] Support parsing 8bit encoded messages 2016-11-28 11:41:16 -08:00
Evan Morikawa
048e077cc5 [local-sync] retry sync after error 2016-11-28 10:39:23 -08:00
Evan Morikawa
2c0c6164ec [local-sync] print sync error when in error state 2016-11-28 10:37:04 -08:00
Juan Tejada
64cb03f4cd Move non shared-models to local sync / remove duplicate DatabaseTypes 2016-11-26 12:48:48 -08:00
Ben Gotow
4bbfd6b906 fix(storage): Move to ~/.nylas-k2 2016-11-23 17:08:38 -08:00
Ben Gotow
5c37abc578 [n1] fix(sync): Add support for message encodings 2016-11-23 17:07:09 -08:00
Ben Gotow
dd28d6b146 [n1] fix(api): Add support for messages?thread_id=1 2016-11-23 16:25:45 -08:00
Ben Gotow
42e20f106c fix(account): 2016-11-23 15:47:49 -08:00
Ben Gotow
e7386ff4ae Gmail auth: resolved settings tests 2016-11-23 15:23:46 -08:00
Juan Tejada
3f050ea150 fix dangling paren 2016-11-23 14:26:24 -08:00
Juan Tejada
f0caf042bd [local-sync]: Restore message-processor
Don't use pubsub for scheduling a message for processing, just use
nextTick
2016-11-23 14:25:15 -08:00
Evan Morikawa
78b96d24ca [local-sync] fix promise instance of check 2016-11-23 14:22:38 -08:00
Evan Morikawa
931943bea6 [local-sync] fix unnecessary transaction JSON parse and binding issue 2016-11-23 13:43:00 -08:00
Juan Tejada
f45425a7b6 [local-sync] Remove unused message-types 2016-11-23 13:30:51 -08:00
Karim Hamidou
43030789a8 Make the delta stream work
Also replaces our LocalPubsubConnector by a TransactionConnector which
just uses EventEmitter.
2016-11-23 13:08:59 -08:00
Evan Morikawa
60801262c7 [local-sync] return as auth_token instead of token for N1 2016-11-23 12:35:48 -08:00
Juan Tejada
f98c38fef4 [iso-core]: Make loadModels reusable by cloud-core 2016-11-23 12:16:58 -08:00
Evan Morikawa
eacbb99f15 rearrange logging so message comes first in console 2016-11-23 12:01:47 -08:00
Karim Hamidou
c05bc8ee63 Remove redis dependency
Conflicts:
	packages/local-sync/src/local-sync-worker/sync-process-manager.js
2016-11-23 11:50:13 -08:00
Juan Tejada
f2a032c87c [iso-core]: Update api for loadModels 2016-11-23 11:49:32 -08:00
Evan Morikawa
edd49c0f4a Use 2578 as port on example 2016-11-23 11:48:48 -08:00
Evan Morikawa
0243edeee3 [local-sync] Remove Gmail auth from local-sync 2016-11-23 11:07:04 -08:00
Juan Tejada
53a1f6e824 [local-sync]: Properly remove all refs to global.Metrics 2016-11-23 11:01:48 -08:00
Evan Morikawa
9707092cc9 Add logger fallback 2016-11-23 10:53:02 -08:00
Karim Hamidou
ba58409f2c Fix module loading bug
Conflicts:
	packages/isomorphic-core/src/models/index.js
	packages/local-sync/package.json
2016-11-23 10:51:03 -08:00
Evan Morikawa
2cce4e0d7d Add sqlite3 since sequelize can't use better-sqlite3 2016-11-23 10:32:07 -08:00
Evan Morikawa
4eacd22846 Fix JSON parsing error 2016-11-23 10:19:35 -08:00
Evan Morikawa
ae42c37606 Add better-sqlite3 2016-11-23 10:18:47 -08:00
Juan Tejada
5b7214e464 [local-sync]: Let local-sync start, add loadModels to iso-core 2016-11-23 10:18:35 -08:00
Evan Morikawa
3fac21458c Update local port to 2578 2016-11-23 10:12:02 -08:00
Evan Morikawa
0793e97f33 [*] package.json updates post lerna bootstrap 2016-11-23 09:33:54 -08:00
Evan Morikawa
1112d3bccd [local-sync] update package.json to include missing deps 2016-11-23 09:27:41 -08:00
Evan Morikawa
d01b4ffe77 [isomorphic-core] Uppdate refs nylas-core => isomorphic-core 2016-11-23 09:12:45 -08:00
Juan Tejada
814e014e39 Final nylas-core and cloud-core cleanup
- Remove unused exported PromiseUtils from cloud-core, import instead
from nylas-core where needed
- Remove unused MessageTypes from cloud-core
- Move MessageTypes from nylas-core to local-sync. It's completely
isolated to local-sync
2016-11-22 20:36:38 -08:00
Juan Tejada
3b7c40a870 [local-sync] Misc fixes from database-connector move 2016-11-22 20:25:43 -08:00
Juan Tejada
792ed2bb5c local[sync] Move missing file for local-syncs database-connector 2016-11-22 20:18:19 -08:00
Juan Tejada
0a24c01b5a [local-sync] fix path for local pubsub-connector 2016-11-22 20:13:35 -08:00
Juan Tejada
957ba73bd0 [local-sync] Make local logger es6 for compilation 2016-11-22 20:10:54 -08:00
Juan Tejada
296846adf5 [local-sync] Remove logger and metrics from local-sync and nylas-core 2016-11-22 20:07:11 -08:00
Evan Morikawa
3ff98f45a9 Rename generic Errors to IMAPErrors 2016-11-22 18:24:46 -08:00
Evan Morikawa
65fafc0390 Move SyncPolicy out of nylas-core to DefaultSyncPolicy 2016-11-22 18:20:34 -08:00
Evan Morikawa
106d7e57a1 Rename DatabaseConnector to LocalDatabaseConnector and move 2016-11-22 17:51:43 -08:00
Evan Morikawa
2b1c787eec Move PubSubConnector to LocalPubSubConnector out of nylas-core 2016-11-22 17:51:43 -08:00
Evan Morikawa
c019e9a23b Move SchedulerUtils out of nylas-core to local-sync/src/shared 2016-11-22 17:07:48 -08:00
Juan Tejada
008a294242 fix(deps) Fix deps for local-sync and nylas-core 2016-11-22 16:55:08 -08:00
Evan Morikawa
951feae657 [local-sync]: moved spec into similarly named folder and updated refs 2016-11-22 16:08:10 -08:00
Evan Morikawa
9e867fa4fd [local-sync]: move folders into src folder 2016-11-22 16:03:38 -08:00
Ben Gotow
18c0ff40ba [cloud] fix(*): More misplaced packages 2016-11-22 15:40:18 -08:00
Evan Morikawa
e772e11196 [local]: rename folder nylas-api to local-api 2016-11-22 15:34:00 -08:00
Halla Moore
845139826b [local-sync] Check for missing Category roles by localized display names
Sometimes imap mailboxes aren't properly flagged with their roles, so we
check the display names against known variations to see if we can find any
missing roles.
2016-11-22 15:31:35 -08:00
Juan Tejada
5e42a7dd9e Merge branch 'master' of github.com:nylas/K2 2016-11-22 15:16:00 -08:00
Juan Tejada
637d3ac6cc fix local-sync package 2016-11-22 15:13:28 -08:00
Evan Morikawa
d4608dd3a6 Update package.json post lerna install 2016-11-22 14:52:42 -08:00
Karim Hamidou
372beeef52 More structure adapts.
Conflicts:
	packages/local-sync/package.json
2016-11-22 14:26:48 -08:00
Karim Hamidou
4d91dcd3a3 Basic structure changes to run K2 in N1 2016-11-22 14:23:16 -08:00
Ben Gotow
424ee4e1d2 [local] Fix package json 2016-11-22 13:55:04 -08:00
Karim Hamidou
0c5dd6ded7 Flesh out skeleton. 2016-11-22 12:25:27 -08:00
Juan Tejada
ddd5641463 fix(folders): Properly update thread folders on sync 2016-11-22 12:24:13 -08:00
Karim Hamidou
3d31150bbb (fix) Set up base structure for local sync. 2016-11-22 12:01:45 -08:00