mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-08 13:44:53 +08:00
fix(sidebar): explicitly detect 202 and cache null people
This commit is contained in:
parent
e8e4761e45
commit
5dbef230a3
3 changed files with 32 additions and 15 deletions
|
@ -13,22 +13,35 @@ module.exports = class ClearbitDataSource
|
|||
user: tok
|
||||
pass: ""
|
||||
path: "/proxy/clearbit/#{@clearbitAPI()}/find?email=#{email}",
|
||||
success: (body) =>
|
||||
resolve(@parseResponse(body))
|
||||
success: (body, response) =>
|
||||
resolve(@parseResponse(body, response, email))
|
||||
error: reject
|
||||
|
||||
# The clearbit -> Nylas adapater
|
||||
parseResponse: (resp={}) ->
|
||||
person = resp.person
|
||||
return null unless person
|
||||
cacheDate: Date.now()
|
||||
email: person.email # Used as checksum
|
||||
bio: person.bio ? person.twitter?.bio ? person.aboutme?.bio,
|
||||
location: person.location ? person.geo?.city
|
||||
currentTitle: person.employment?.title,
|
||||
currentEmployer: person.employment?.name,
|
||||
profilePhotoUrl: person.avatar,
|
||||
socialProfiles: @_socialProfiles(person)
|
||||
parseResponse: (body={}, response, requestedEmail) ->
|
||||
# This means it's in the process of fetching. Return null so we don't
|
||||
# cache and try again.
|
||||
if response.statusCode isnt 200
|
||||
return null
|
||||
|
||||
person = body.person
|
||||
|
||||
# This means there was no data about the person available. Return a
|
||||
# valid, but empty object for us to cache. This can happen when we
|
||||
# have company data, but no personal data.
|
||||
if not person
|
||||
return {email: requestedEmail}
|
||||
|
||||
return {
|
||||
cacheDate: Date.now()
|
||||
email: person.email # Used as checksum
|
||||
bio: person.bio ? person.twitter?.bio ? person.aboutme?.bio,
|
||||
location: person.location ? person.geo?.city
|
||||
currentTitle: person.employment?.title,
|
||||
currentEmployer: person.employment?.name,
|
||||
profilePhotoUrl: person.avatar,
|
||||
socialProfiles: @_socialProfiles(person)
|
||||
}
|
||||
|
||||
_socialProfiles: (person={}) ->
|
||||
profiles = {}
|
||||
|
|
|
@ -24,7 +24,11 @@ class ParticipantProfileStore extends NylasStore {
|
|||
}
|
||||
|
||||
if (this.inCache(contact)) {
|
||||
return this.getCache(contact)
|
||||
const data = this.getCache(contact);
|
||||
if (data.cacheDate) {
|
||||
return data
|
||||
}
|
||||
return {}
|
||||
}
|
||||
|
||||
this.dataSource.find({email: contact.email}).then((data) => {
|
||||
|
|
|
@ -53,7 +53,7 @@ class EdgehillAPI
|
|||
if error? or response.statusCode > 299
|
||||
options.error(new APIError({error:error, response:response, body:body, requestOptions: options}))
|
||||
else
|
||||
options.success(body) if options.success
|
||||
options.success(body, response) if options.success
|
||||
|
||||
_defaultErrorCallback: (apiError) ->
|
||||
console.error(apiError)
|
||||
|
|
Loading…
Add table
Reference in a new issue