mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-12-29 11:52:34 +08:00
42ad243824
- The FocusedContactStore was triggering too often, and leaving it up to the FullcontactStore to fetch the full Contact model for the focused contact (pulled from thread.) The FocusedContactStore triggers more responsibly, and registering for the role "MessageListSidebar:ContactCard" now gives you the focused contact as a full database model. The whole ContactCard region also fades in and out.
38 lines
1.1 KiB
CoffeeScript
38 lines
1.1 KiB
CoffeeScript
_ = require 'underscore'
|
|
Reflux = require 'reflux'
|
|
request = require 'request'
|
|
{Contact,
|
|
AccountStore
|
|
ContactStore,
|
|
DatabaseStore,
|
|
FocusedContactsStore} = require 'nylas-exports'
|
|
|
|
FullContactStore = Reflux.createStore
|
|
init: ->
|
|
|
|
dataForContact: (contact) ->
|
|
return {} unless contact
|
|
if contact.thirdPartyData["FullContact"]
|
|
return contact.thirdPartyData["FullContact"]
|
|
else
|
|
@_attachFullcontactDataToContact(contact)
|
|
return {}
|
|
|
|
_attachFullcontactDataToContact: (contact) ->
|
|
email = contact.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)
|
|
contact.title = data.organizations?[0]?["title"]
|
|
contact.company = data.organizations?[0]?["name"]
|
|
contact.thirdPartyData ?= {}
|
|
contact.thirdPartyData["FullContact"] = data
|
|
DatabaseStore.persistModel(contact)
|
|
@trigger()
|
|
|
|
module.exports = FullContactStore
|