🎨(contact): Reuse AccountStore.accountForEmail inside isMe

This commit is contained in:
Juan Tejada 2016-02-07 01:30:11 -08:00
parent ed0562fe2c
commit 2655054e34
3 changed files with 4 additions and 16 deletions

View file

@ -133,9 +133,6 @@ describe "Contact", ->
expect(c1.isMe()).toBe(true)
it "also matches any aliases you've created", ->
spyOn(AccountStore, 'aliases').andReturn [
new Contact(name: 'Ben Other', email: 'ben22@nylas.com', accountId: TEST_ACCOUNT_ID)
]
spyOn(AccountStore, 'accounts').andReturn [
new Account
provider: "gmail"

View file

@ -95,20 +95,11 @@ class Contact extends Model
# You should use this method instead of comparing the user's email address to
# the account email, since it is case-insensitive and future-proof.
isMe: ->
@isMeAccount() isnt null
isMeAccount: ->
for account in AccountStore.accounts()
if Utils.emailIsEquivalent(@email, account.emailAddress)
return account
for alias in AccountStore.aliases()
if Utils.emailIsEquivalent(@email, alias.email)
return AccountStore.accountForId(alias.accountId)
return null
account = AccountStore.accountForEmail(@email)
return account?
isMePhrase: ({includeAccountLabel} = {}) ->
account = @isMeAccount()
account = AccountStore.accountForEmail(@email)
return null unless account
if includeAccountLabel

View file

@ -132,7 +132,7 @@ class AccountStore extends NylasStore
# Public: Returns the {Account} for the given email address, or null.
accountForEmail: (email) =>
@_cachedGetter "accountForEmail:#{email}", =>
_.find @_accounts, (account) ->
_.find @accounts(), (account) ->
return true if Utils.emailIsEquivalent(email, account.emailAddress)
for alias in account.aliases
aliasContact = account.meUsingAlias(alias)