[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.
This commit is contained in:
Christine Spang 2016-12-02 14:10:54 -08:00
parent d9f3edad0f
commit 9752eea9f7
2 changed files with 6 additions and 0 deletions

View file

@ -2,6 +2,7 @@ const {DatabaseTypes: {JSONARRAYType}} = require('isomorphic-core');
module.exports = (sequelize, Sequelize) => {
return sequelize.define('thread', {
id: { type: Sequelize.STRING(65), primaryKey: true },
accountId: { type: Sequelize.STRING, allowNull: false },
version: Sequelize.INTEGER,
remoteThreadId: Sequelize.STRING,

View file

@ -95,6 +95,11 @@ function detectThread({db, message}) {
// update the basic properties of the thread
thread.accountId = message.accountId;
// Threads may, locally, have the ID of any message within the thread
// (message IDs are globally unique, even across accounts!)
if (!thread.id) {
thread.id = `t:${message.id}`
}
// update the participants on the thread
const threadParticipants = [].concat(thread.participants);