mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-23 00:36:50 +08:00
30 lines
863 B
CoffeeScript
30 lines
863 B
CoffeeScript
|
|
||
|
RefreshingJSONCache = require './refreshing-json-cache'
|
||
|
{NylasAPI} = require 'nylas-exports'
|
||
|
|
||
|
# Stores contact rankings
|
||
|
class ContactRankingsCache extends RefreshingJSONCache
|
||
|
constructor: (accountId) ->
|
||
|
@_accountId = accountId
|
||
|
super({
|
||
|
key: "ContactRankingsFor#{accountId}",
|
||
|
version: 1,
|
||
|
refreshInterval: 60 * 60 * 1000 * 24 # one day
|
||
|
})
|
||
|
|
||
|
fetchData: (callback) =>
|
||
|
NylasAPI.makeRequest
|
||
|
accountId: @_accountId
|
||
|
path: "/contacts/rankings"
|
||
|
returnsModel: false
|
||
|
.then (json) =>
|
||
|
# Convert rankings into the format needed for quick lookup
|
||
|
rankings = {}
|
||
|
for [email, rank] in json
|
||
|
rankings[email.toLowerCase()] = rank
|
||
|
callback(rankings)
|
||
|
.catch (err) =>
|
||
|
console.warn("Request for Contact Rankings failed for account #{@_accountId}. #{err}")
|
||
|
|
||
|
|
||
|
module.exports = ContactRankingsCache
|