diff --git a/js/database.js b/js/database.js index 8f40c1a86..d6a52aa58 100644 --- a/js/database.js +++ b/js/database.js @@ -49,6 +49,25 @@ }); }); } + }, + { + version: "3.0", + migrate: function(transaction, next) { + var conversations = transaction.objectStore("items"); + + var all = new Whisper.ConversationCollection(); + all.fetch().then(function() { + var unreadCount = all.reduce(function(total, model) { + var count = model.get('unreadCount'); + if (count === undefined) { + count = 0; + } + return total + count; + }, 0); + storage.remove('unreadCount'); + storage.put('unreadCount', unreadCount); + }); + } } ]; }());