mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-12 12:40:08 +08:00
4619871e8d
Summary: Fixes: T1334 remove final InboxApp references move out all underscore-plus methods Mass find and replace of underscore-plus sed -i '' -- 's/underscore-plus/underscore/g' **/*.coffee sed -i '' -- 's/underscore-plus/underscore/g' **/*.cjsx Test Plan: edgehill --test Reviewers: bengotow Reviewed By: bengotow Differential Revision: https://phab.nylas.com/D1534
43 lines
1.2 KiB
CoffeeScript
43 lines
1.2 KiB
CoffeeScript
Reflux = require 'reflux'
|
|
_ = require 'underscore'
|
|
{DatabaseStore, NamespaceStore, Actions, Thread} = require 'nylas-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?("")
|