Reset unreadCounts

Add a migration to reset bad unreadCounts from previously broken
unreadCount tracking. This will execute exactly once per installation.

// FREEBIE
This commit is contained in:
lilia 2015-11-19 17:19:04 -08:00
parent 31b29b67f2
commit ed32801c3e
1 changed files with 19 additions and 0 deletions

View File

@ -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);
});
}
}
];
}());