mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-11 01:54:40 +08:00
🎨(contact): Reuse AccountStore.accountForEmail inside isMe
This commit is contained in:
parent
ed0562fe2c
commit
2655054e34
3 changed files with 4 additions and 16 deletions
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue