Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
This PR introduces a new MessageChannelMessage table. This table represents the link between a message and a channel. Meaning we can have the same message imported by different channels and we will only store 1 message, this new table will be there to map the relation. Because of this, we had to introduce some merging strategies. This PR handles a few edges cases but it still need to be tested.
Details
Message has already been imported and has been matched with messageHeaderId
1.1) Message has the same threadExternalId
=> We only create a new row in MessageChannelMessage using the info from gmail and the existing message.
1.2) Message has a different threadExternalId. Meaning it was imported through a different Channel. We need to merge.
Message does not exist but we can find a thread with threadExternalId
=> We create a message and messageChannelMessage
Message does not exist and we can't find a matching thread.
=> We create a new thread.
Note: I've removed the sanitising of empty threads. Also we will need to delete messages that don't have an entry in messageChannelMessage. We will add it back in an upcoming PR with probably a dedicated job.