Mailspring/packages/client-app/internal_packages/deltas/lib/contact-rankings-cache.es6
Evan Morikawa ba1f429928 [client-app] deprecate returnsModel param for nylas-api-request
Summary:
We no longer need to use the `returnsModel` param since we get all of our
models through the in memory delta stream. There were a ton of places
unnecessarily passing `returnsModel: false` when it defaults to false in
the first place

Depends on D4057

Test Plan: manual

Reviewers: halla, spang, juan

Reviewed By: spang, juan

Differential Revision: https://phab.nylas.com/D4065
2017-03-01 12:13:08 -08:00

49 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