Download Gmail threads oldest-to-newest for better reconciliation.
Download Gmail threads oldest-to-newest for better reconciliation.

Summary:
This fixes the following situation:
1) You send a message via the Inbox API. We create a Message object m1 and thread t1.

2) Somebody replies to that message.

3) We sync that reply, and create a new message m2 and new thread t2.

4) We sync the next oldest message in the thread, which was the message we sent originally. How do we reconcile? Currently, we don't create a new thread, and just update t1 with the g_thrid. But now we've actually split the thread across t1 and t2, and have two objects with the same g_thrid. That's not good.

You could imagine alternatively deleting m1 and t1 at this point, and adding a
new message m3 onto t2. But this breaks the API for users who might want to do
things like "check the original thread t1 for replies to the message that they
sent via the API".

So this seems like the best alternative solution to me. Now the first message
you sync is your original one, so the replies can be bolted on to t1.
This adds a few seconds of latency if you get new mail on a long thread during
initial sync, but that seems like a relatively small cost.

Test Plan: Not really sure how to programatically test this :/

Reviewers: spang

Reviewed By: spang

Subscribers: khamidou

Differential Revision: https://review.inboxapp.com/D535

wakermahmud/sync-engine,PriviPK/privipk-sync-engine,jobscore/sync-engine,wakermahmud/sync-engine,ErinCall/sync-engine,PriviPK/privipk-sync-engine,nylas/sync-engine,EthanBlackburn/sync-engine,nylas/sync-engine,EthanBlackburn/sync-engine,closeio/nylas,PriviPK/privipk-sync-engine,ErinCall/sync-engine,EthanBlackburn/sync-engine,Eagles2F/sync-engine,PriviPK/privipk-sync-engine,gale320/sync-engine,EthanBlackburn/sync-engine,EthanBlackburn/sync-engine,Eagles2F/sync-engine,gale320/sync-engine,closeio/nylas,nylas/sync-engine,Eagles2F/sync-engine,gale320/sync-engine,nylas/sync-engine,gale320/sync-engine,wakermahmud/sync-engine,jobscore/sync-engine,ErinCall/sync-engine,wakermahmud/sync-engine,closeio/nylas,PriviPK/privipk-sync-engine,Eagles2F/sync-engine,jobscore/sync-engine,closeio/nylas,gale320/sync-engine,ErinCall/sync-engine,jobscore/sync-engine,wakermahmud/sync-engine,Eagles2F/sync-engine,ErinCall/sync-engine