mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-02-24 16:14:01 +08:00
Summary: custom options with tests speed changes Test Plan: edgehill --test Reviewers: bengotow Reviewed By: bengotow Differential Revision: https://review.inboxapp.com/D1383
43 lines
1.4 KiB
CoffeeScript
43 lines
1.4 KiB
CoffeeScript
_ = require 'underscore-plus'
|
|
Reflux = require 'reflux'
|
|
request = require 'request'
|
|
{FocusedContactsStore} = require 'inbox-exports'
|
|
|
|
module.exports =
|
|
FullContactStore = Reflux.createStore
|
|
|
|
init: ->
|
|
@_fetchAPIData = _.debounce(_.bind(@__fetchAPIData, @), 50)
|
|
@_cachedContactData = {}
|
|
@listenTo FocusedContactsStore, @_onFocusedContacts
|
|
|
|
sortedContacts: -> FocusedContactsStore.sortedContacts()
|
|
focusedContact: -> FocusedContactsStore.focusedContact()
|
|
|
|
fullContactCache: ->
|
|
emails = {}
|
|
contacts = FocusedContactsStore.sortedContacts()
|
|
emails[contact.email] = contact for contact in contacts
|
|
fullContactCache = {}
|
|
_.each @_cachedContactData, (fullContactData, email) ->
|
|
if email of emails then fullContactCache[email] = fullContactData
|
|
return fullContactCache
|
|
|
|
_onFocusedContacts: ->
|
|
contact = FocusedContactsStore.focusedContact() ? {}
|
|
if not @_cachedContactData[contact.email]
|
|
@_fetchAPIData(contact.email)
|
|
@trigger()
|
|
|
|
__fetchAPIData: (email="") ->
|
|
# Swap the url's to see real data
|
|
email = email.toLowerCase().trim()
|
|
return if email.length is 0
|
|
url = "https://api.fullcontact.com/v2/person.json?email=#{email}&apiKey=eadcbaf0286562a"
|
|
request url, (err, resp, data) =>
|
|
return {} if err
|
|
return {} if resp.statusCode != 200
|
|
try
|
|
data = JSON.parse data
|
|
@_cachedContactData[email] = data
|
|
@trigger(@)
|