From dd7140ee1fc358732871194fc65d5b8bbd9aa97a Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Mon, 3 Aug 2015 18:52:07 -0700 Subject: [PATCH] fix(threads): Use last_message_timestamp fallback until migration has completed --- src/flux/models/thread.coffee | 7 +++++++ src/flux/stores/database-store.coffee | 14 ++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/flux/models/thread.coffee b/src/flux/models/thread.coffee index 66ac6079f..f405eaef6 100644 --- a/src/flux/models/thread.coffee +++ b/src/flux/models/thread.coffee @@ -86,6 +86,13 @@ class Thread extends Model setup: -> ['CREATE INDEX IF NOT EXISTS ThreadListIndex ON Thread(last_message_received_timestamp DESC, namespace_id, id)'] + fromJSON: (json) -> + super(json) + + # TODO: This is temporary, waiting on a migration on the backend + @lastMessageReceivedTimestamp ||= new Date(json['last_message_timestamp'] * 1000) + @ + # Public: Returns true if the thread has a {Category} with the given ID. # # * `id` A {String} {Category} ID diff --git a/src/flux/stores/database-store.coffee b/src/flux/stores/database-store.coffee index 9fa406a66..7d6b41443 100644 --- a/src/flux/stores/database-store.coffee +++ b/src/flux/stores/database-store.coffee @@ -17,7 +17,7 @@ PriorityUICoordinator = require '../../priority-ui-coordinator' generateTempId, isTempId} = require '../models/utils' -DatabaseVersion = 5 +DatabaseVersion = 6 DatabasePhase = Setup: 'setup' @@ -100,13 +100,13 @@ class DatabaseStore extends NylasStore if phase is DatabasePhase.Setup and atom.isMainWindow() @_openDatabase => - @_runDatabaseSetup => - @_checkDatabaseVersion => + @_checkDatabaseVersion {allowNotSet: true}, => + @_runDatabaseSetup => app.setDatabasePhase(DatabasePhase.Ready) else if phase is DatabasePhase.Ready @_openDatabase => - @_checkDatabaseVersion => + @_checkDatabaseVersion {}, => @_open = true w() for w in @_waiting @_waiting = [] @@ -130,10 +130,12 @@ class DatabaseStore extends NylasStore return @_handleSetupError(err) if err ready() - _checkDatabaseVersion: (ready) => + _checkDatabaseVersion: ({allowNotSet} = {}, ready) => @_db.get 'PRAGMA user_version', (err, {user_version}) => return @_handleSetupError(err) if err - if user_version/1 isnt DatabaseVersion + emptyVersion = user_version is 0 + wrongVersion = user_version/1 isnt DatabaseVersion + if wrongVersion and not (emptyVersion and allowNotSet) return @_handleSetupError(new Error("Incorrect database schema version: #{user_version} not #{DatabaseVersion}")) ready()