mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-14 21:57:55 +08:00
da463c250f
Summary: This commit consolidates the `DeltaConnectionStatusStore` and the `DeltaConnectionStore` which kept track of very similar state and made sense to be the same store (as per feedback in D4118#77647) Given that this state needs to be available app-wide for plugins to query the status of delta connections, `internal_packages/deltas` was removed (given that it only activated that store), in favor of having the unified store inside `src/flux/stores` and available via `nylas-exports` The `deltas` package also contained some contacts-ranking code, which is no longer in use until we restore that fetaure, so I created a `internal_packages/contact-rankings` which contains this unused code for now. Test Plan: manually open, close, end delta connections, verify that I'm getting correct results. unit tests to come Reviewers: halla, spang, evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D4145
48 lines
1.1 KiB
JavaScript
48 lines
1.1 KiB
JavaScript
import {
|
|
NylasAPI,
|
|
NylasAPIRequest,
|
|
} from 'nylas-exports'
|
|
import RefreshingJSONCache from './refreshing-json-cache'
|
|
|
|
|
|
// Stores contact rankings
|
|
class ContactRankingsCache extends RefreshingJSONCache {
|
|
constructor(accountId) {
|
|
super({
|
|
key: `ContactRankingsFor${accountId}`,
|
|
version: 1,
|
|
refreshInterval: 60 * 60 * 1000 * 24, // one day
|
|
})
|
|
this._accountId = accountId
|
|
}
|
|
|
|
fetchData = (callback) => {
|
|
if (NylasEnv.inSpecMode()) return
|
|
|
|
const request = new NylasAPIRequest({
|
|
api: NylasAPI,
|
|
options: {
|
|
accountId: this._accountId,
|
|
path: "/contacts/rankings",
|
|
},
|
|
})
|
|
|
|
request.run()
|
|
.then((json) => {
|
|
if (!json || !(json instanceof Array)) return
|
|
|
|
// Convert rankings into the format needed for quick lookup
|
|
const rankings = {}
|
|
for (const [email, rank] of json) {
|
|
rankings[email.toLowerCase()] = rank
|
|
}
|
|
callback(rankings)
|
|
})
|
|
.catch((err) => {
|
|
console.warn(`Request for Contact Rankings failed for
|
|
account ${this._accountId}. ${err}`)
|
|
})
|
|
}
|
|
}
|
|
|
|
export default ContactRankingsCache
|