Mailspring/internal_packages/unread-badge/lib/unread-badge-store.coffee
Ben Gotow 0bd303865e fix(friday): Bugs and initial pass at the Today view without content (see summary)
Summary:
Load unread counts from database again, not tags

fix(multiselect-list): Clear selection on esc

fix(onboarding): Make target=_blank links work in onboarding pages

fix(workspace): Items in header and footer regions are in a single column

fix(layout): Critical issue for things not 100% height

fix(activity-bar): Show in dev mode so you know you're in dev mode

fix(quoted-text): Support for #divRplyFwdMsg quoted text marker

Test Plan: Run specs

Reviewers: evan

Reviewed By: evan

Differential Revision: https://review.inboxapp.com/D1484
2015-05-08 16:36:48 -07:00

43 lines
1.2 KiB
CoffeeScript

Reflux = require 'reflux'
_ = require 'underscore-plus'
{DatabaseStore, NamespaceStore, Actions, Thread} = require 'inbox-exports'
remote = require 'remote'
app = remote.require 'app'
AppUnreadCount = null
module.exports =
AppUnreadBadgeStore = Reflux.createStore
init: ->
@listenTo NamespaceStore, @_onNamespaceChanged
@listenTo DatabaseStore, @_onDataChanged
@_fetchCount()
_onNamespaceChanged: ->
@_onDataChanged()
_onDataChanged: (change) ->
return app.dock?.setBadge?("") unless NamespaceStore.current()
if change && change.objectClass is Thread.name
@_fetchCountDebounced ?= _.debounce(@_fetchCount, 5000)
@_fetchCountDebounced()
_fetchCount: ->
namespace = NamespaceStore.current()
return unless namespace
DatabaseStore.count(Thread, [
Thread.attributes.namespaceId.equal(namespace.id),
Thread.attributes.unread.equal(true),
Thread.attributes.tags.contains('inbox')
]).then (count) ->
return if AppUnreadCount is count
AppUnreadCount = count
if count > 999
app.dock?.setBadge?("\u221E")
else if count > 0
app.dock?.setBadge?("#{count}")
else
app.dock?.setBadge?("")