diff options
author | François Schmidts <francois.schmidts@gmail.com> | 2016-02-02 21:55:57 +0100 |
---|---|---|
committer | François Schmidts <francois.schmidts@gmail.com> | 2016-02-02 21:55:57 +0100 |
commit | ded0971f5691ed2934e690c8d7bd480ed15402f7 (patch) | |
tree | 0695b1792674a6b12d9e165429554f524f00c8ef /src/web/js/stores/MenuStore.js | |
parent | ordering categories in the feed form (diff) | |
download | newspipe-ded0971f5691ed2934e690c8d7bd480ed15402f7.tar.gz newspipe-ded0971f5691ed2934e690c8d7bd480ed15402f7.tar.bz2 newspipe-ded0971f5691ed2934e690c8d7bd480ed15402f7.zip |
updating unread count when fetching unread
Diffstat (limited to 'src/web/js/stores/MenuStore.js')
-rw-r--r-- | src/web/js/stores/MenuStore.js | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/src/web/js/stores/MenuStore.js b/src/web/js/stores/MenuStore.js index d3c44355..36dee363 100644 --- a/src/web/js/stores/MenuStore.js +++ b/src/web/js/stores/MenuStore.js @@ -56,12 +56,34 @@ MenuStore.dispatchToken = JarrDispatcher.register(function(action) { break; case ActionTypes.PARENT_FILTER: MenuStore.setActive(action.filter_type, action.filter_id); - break; - case ActionTypes.MENU_FILTER: - MenuStore.setFilter(action.filter); - break; - case ActionTypes.MENU_FILTER: - MenuStore.setFilter(action.filter); + if(action.filters && action.articles && !action.filters.query + && action.filters.filter == 'unread') { + var new_unread = {}; + action.articles.map(function(article) { + if(!(article.feed_id in new_unread)) { + new_unread[article.feed_id] = 0; + } + if(!article.read) { + new_unread[article.feed_id] += 1; + } + }); + var changed = false; + for(var feed_id in new_unread) { + var old_unread = MenuStore._datas.feeds[feed_id].unread; + if(old_unread == new_unread[feed_id]) { + continue; + } + changed = true; + MenuStore._datas.feeds[feed_id].unread = new_unread[feed_id]; + var cat_id = MenuStore._datas.feeds[feed_id].category_id; + MenuStore._datas.categories[cat_id].unread -= old_unread; + MenuStore._datas.categories[cat_id].unread += new_unread[feed_id]; + } + if(changed) { + MenuStore.emitChange(); + } + } + break; case ActionTypes.MENU_FILTER: MenuStore.setFilter(action.filter); |