mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-03-10 06:56:09 +08:00
fix(sync-messaging): Update other messaging to check per-folder sync status
Summary: Also fixes an issue where accounts weren't being removed from NylasSyncStatusStore because `subscriptions` was used instead of `_subscriptions`. Specifically, rename `_subscriptions` to `_accountSubscriptions` so we get an explicit runtime error if the `_` is left out. Test Plan: tested locally Reviewers: evan, juan Reviewed By: juan Differential Revision: https://phab.nylas.com/D3671
This commit is contained in:
parent
945ea5a4fc
commit
8f39eefeb1
2 changed files with 26 additions and 15 deletions
|
@ -83,15 +83,16 @@ class EmptyListState extends React.Component
|
|||
|
||||
constructor: (@props) ->
|
||||
@_mounted = false
|
||||
@state =
|
||||
syncing: NylasSyncStatusStore.busy()
|
||||
@state = Object.assign
|
||||
active: false
|
||||
rect: {}
|
||||
@_getStateFromStores()
|
||||
|
||||
componentDidMount: ->
|
||||
@_mounted = true
|
||||
@_unlisteners = []
|
||||
@_unlisteners.push NylasSyncStatusStore.listen(@_onChange, @)
|
||||
@_unlisteners.push NylasSyncStatusStore.listen((=> @setState @_getStateFromStores()), @)
|
||||
@_unlisteners.push FocusedPerspectiveStore.listen((=> @setState @_getStateFromStores()), @)
|
||||
window.addEventListener('resize', @_onResize)
|
||||
if @props.visible and not @state.active
|
||||
rect = @_getDimensions()
|
||||
|
@ -149,8 +150,18 @@ class EmptyListState extends React.Component
|
|||
if rect
|
||||
@setState({rect})
|
||||
|
||||
_onChange: ->
|
||||
@setState
|
||||
syncing: NylasSyncStatusStore.busy()
|
||||
_getStateFromStores: ->
|
||||
currentPerspective = FocusedPerspectiveStore.current()
|
||||
accountIds = currentPerspective.accountIds
|
||||
if accountIds.length == 1
|
||||
accountId = accountIds[0]
|
||||
categories = currentPerspective.categories
|
||||
folderName = null
|
||||
if categories.length == 1 and categories[0].object == 'folder'
|
||||
folderName = categories[0].displayName
|
||||
syncing = !NylasSyncStatusStore.isSyncCompleteForAccount(accountId, folderName)
|
||||
else
|
||||
syncing = NylasSyncStatusStore.busy()
|
||||
return syncing: syncing
|
||||
|
||||
module.exports = EmptyListState
|
||||
|
|
|
@ -40,7 +40,7 @@ class NylasSyncStatusStore extends NylasStore {
|
|||
constructor() {
|
||||
super()
|
||||
this._statesByAccount = {}
|
||||
this._subscriptions = new Map()
|
||||
this._accountSubscriptions = new Map()
|
||||
this._triggerDebounced = _.debounce(this.trigger, 100)
|
||||
|
||||
this.listenTo(AccountStore, () => this._onAccountsChanged())
|
||||
|
@ -54,28 +54,28 @@ class NylasSyncStatusStore extends NylasStore {
|
|||
}, 30 * 1000)
|
||||
|
||||
this._onCategoriesChanged()
|
||||
this._setupSubscriptions(AccountStore.accountIds())
|
||||
this._setupAccountSubscriptions(AccountStore.accountIds())
|
||||
}
|
||||
|
||||
_setupSubscriptions(accountIds) {
|
||||
_setupAccountSubscriptions(accountIds) {
|
||||
accountIds.forEach((accountId) => {
|
||||
if (this._subscriptions.has(accountId)) { return; }
|
||||
if (this._accountSubscriptions.has(accountId)) { return; }
|
||||
const query = DatabaseStore.findJSONBlob(`NylasSyncWorker:${accountId}`)
|
||||
const sub = Rx.Observable.fromQuery(query)
|
||||
.subscribe((json) => this._updateState(accountId, json))
|
||||
this._subscriptions.set(accountId, sub)
|
||||
this._accountSubscriptions.set(accountId, sub)
|
||||
})
|
||||
}
|
||||
|
||||
_onAccountsChanged() {
|
||||
const currentIds = Array.from(this.subscriptions.keys())
|
||||
const currentIds = Array.from(this._accountSubscriptions.keys())
|
||||
const nextIds = AccountStore.accountIds()
|
||||
const newIds = _.difference(nextIds, currentIds)
|
||||
const removedIds = _.difference(currentIds, nextIds)
|
||||
|
||||
removedIds.forEach((accountId) => {
|
||||
if (this._subscriptions.has(accountId)) {
|
||||
this._subscriptions.get(accountId).dispose()
|
||||
if (this._accountSubscriptions.has(accountId)) {
|
||||
this._accountSubscriptions.get(accountId).dispose()
|
||||
}
|
||||
|
||||
if (this._statesByAccount[accountId]) {
|
||||
|
@ -83,7 +83,7 @@ class NylasSyncStatusStore extends NylasStore {
|
|||
this._triggerDebounced()
|
||||
}
|
||||
})
|
||||
this._setupSubscriptions(newIds)
|
||||
this._setupAccountSubscriptions(newIds)
|
||||
}
|
||||
|
||||
_onCategoriesChanged() {
|
||||
|
|
Loading…
Reference in a new issue