From ed32801c3ecb927d847878aec46f824691996648 Mon Sep 17 00:00:00 2001 From: lilia Date: Thu, 19 Nov 2015 17:19:04 -0800 Subject: [PATCH] Reset unreadCounts Add a migration to reset bad unreadCounts from previously broken unreadCount tracking. This will execute exactly once per installation. // FREEBIE --- js/database.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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); + }); + } } ]; }());