diff --git a/packages/local-sync/src/models/thread.js b/packages/local-sync/src/models/thread.js index 7342c3142..6b588ee6a 100644 --- a/packages/local-sync/src/models/thread.js +++ b/packages/local-sync/src/models/thread.js @@ -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, diff --git a/packages/local-sync/src/new-message-processor/detect-thread.js b/packages/local-sync/src/new-message-processor/detect-thread.js index e5ed3b42c..8cf15d8fb 100644 --- a/packages/local-sync/src/new-message-processor/detect-thread.js +++ b/packages/local-sync/src/new-message-processor/detect-thread.js @@ -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);