mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-01 13:14:16 +08:00
feat(me): Display "Me (Account Label)" in unified inbox
This commit is contained in:
parent
b548707671
commit
395b7b9226
5 changed files with 36 additions and 13 deletions
|
@ -26,6 +26,8 @@ pathwatcher = require 'pathwatcher'
|
||||||
TaskQueue,
|
TaskQueue,
|
||||||
AccountStore,
|
AccountStore,
|
||||||
DatabaseStore,
|
DatabaseStore,
|
||||||
|
MailboxPerspective,
|
||||||
|
FocusedPerspectiveStore,
|
||||||
ComponentRegistry} = require "nylas-exports"
|
ComponentRegistry} = require "nylas-exports"
|
||||||
|
|
||||||
NylasEnv.themes.loadBaseStylesheets()
|
NylasEnv.themes.loadBaseStylesheets()
|
||||||
|
@ -170,6 +172,8 @@ beforeEach ->
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
|
|
||||||
|
FocusedPerspectiveStore._current = MailboxPerspective.forNothing()
|
||||||
|
|
||||||
# reset config before each spec; don't load or save from/to `config.json`
|
# reset config before each spec; don't load or save from/to `config.json`
|
||||||
spyOn(Config::, 'load')
|
spyOn(Config::, 'load')
|
||||||
spyOn(Config::, 'save')
|
spyOn(Config::, 'save')
|
||||||
|
|
|
@ -20,14 +20,15 @@ describe "registeredObjectReviver / registeredObjectReplacer", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@testThread = new Thread
|
@testThread = new Thread
|
||||||
id: 'local-1'
|
id: 'local-1'
|
||||||
|
accountId: '1'
|
||||||
participants: [
|
participants: [
|
||||||
new Contact(id: 'local-a', name: 'Juan', email:'juan@nylas.com'),
|
new Contact(id: 'local-a', name: 'Juan', email:'juan@nylas.com', accountId: '1'),
|
||||||
new Contact(id: 'local-b', name: 'Ben', email:'ben@nylas.com')
|
new Contact(id: 'local-b', name: 'Ben', email:'ben@nylas.com', accountId: '1')
|
||||||
]
|
]
|
||||||
subject: 'Test 1234'
|
subject: 'Test 1234'
|
||||||
|
|
||||||
it "should serialize and de-serialize models correctly", ->
|
it "should serialize and de-serialize models correctly", ->
|
||||||
expectedString = '[{"client_id":"local-1","subject":"Test 1234","participants":[{"client_id":"local-a","name":"Juan","email":"juan@nylas.com","thirdPartyData":{},"id":"local-a"},{"client_id":"local-b","name":"Ben","email":"ben@nylas.com","thirdPartyData":{},"id":"local-b"}],"id":"local-1","__constructorName":"Thread"}]'
|
expectedString = '[{"client_id":"local-1","account_id":"1","subject":"Test 1234","participants":[{"client_id":"local-a","account_id":"1","name":"Juan","email":"juan@nylas.com","thirdPartyData":{},"id":"local-a"},{"client_id":"local-b","account_id":"1","name":"Ben","email":"ben@nylas.com","thirdPartyData":{},"id":"local-b"}],"id":"local-1","__constructorName":"Thread"}]'
|
||||||
|
|
||||||
jsonString = JSON.stringify([@testThread], Utils.registeredObjectReplacer)
|
jsonString = JSON.stringify([@testThread], Utils.registeredObjectReplacer)
|
||||||
expect(jsonString).toEqual(expectedString)
|
expect(jsonString).toEqual(expectedString)
|
||||||
|
@ -37,7 +38,7 @@ describe "registeredObjectReviver / registeredObjectReplacer", ->
|
||||||
it "should re-inflate Models in places they're not explicitly declared types", ->
|
it "should re-inflate Models in places they're not explicitly declared types", ->
|
||||||
b = new JSONBlob({id: "local-ThreadsToProcess", json: [@testThread]})
|
b = new JSONBlob({id: "local-ThreadsToProcess", json: [@testThread]})
|
||||||
jsonString = JSON.stringify(b, Utils.registeredObjectReplacer)
|
jsonString = JSON.stringify(b, Utils.registeredObjectReplacer)
|
||||||
expectedString = '{"client_id":"local-ThreadsToProcess","server_id":"local-ThreadsToProcess","json":[{"client_id":"local-1","subject":"Test 1234","participants":[{"client_id":"local-a","name":"Juan","email":"juan@nylas.com","thirdPartyData":{},"id":"local-a"},{"client_id":"local-b","name":"Ben","email":"ben@nylas.com","thirdPartyData":{},"id":"local-b"}],"id":"local-1","__constructorName":"Thread"}],"id":"local-ThreadsToProcess","__constructorName":"JSONBlob"}'
|
expectedString = '{"client_id":"local-ThreadsToProcess","server_id":"local-ThreadsToProcess","json":[{"client_id":"local-1","account_id":"1","subject":"Test 1234","participants":[{"client_id":"local-a","account_id":"1","name":"Juan","email":"juan@nylas.com","thirdPartyData":{},"id":"local-a"},{"client_id":"local-b","account_id":"1","name":"Ben","email":"ben@nylas.com","thirdPartyData":{},"id":"local-b"}],"id":"local-1","__constructorName":"Thread"}],"id":"local-ThreadsToProcess","__constructorName":"JSONBlob"}'
|
||||||
|
|
||||||
expect(jsonString).toEqual(expectedString)
|
expect(jsonString).toEqual(expectedString)
|
||||||
revived = JSON.parse(jsonString, Utils.registeredObjectReviver)
|
revived = JSON.parse(jsonString, Utils.registeredObjectReviver)
|
||||||
|
|
|
@ -3,6 +3,7 @@ Utils = require './utils'
|
||||||
Attributes = require '../attributes'
|
Attributes = require '../attributes'
|
||||||
RegExpUtils = require '../../regexp-utils'
|
RegExpUtils = require '../../regexp-utils'
|
||||||
AccountStore = require '../stores/account-store'
|
AccountStore = require '../stores/account-store'
|
||||||
|
FocusedPerspectiveStore = null # Circular Dependency
|
||||||
_ = require 'underscore'
|
_ = require 'underscore'
|
||||||
|
|
||||||
name_prefixes = {}
|
name_prefixes = {}
|
||||||
|
@ -94,27 +95,37 @@ class Contact extends Model
|
||||||
# You should use this method instead of comparing the user's email address to
|
# 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.
|
# the account email, since it is case-insensitive and future-proof.
|
||||||
isMe: ->
|
isMe: ->
|
||||||
|
@isMeAccount() isnt null
|
||||||
|
|
||||||
|
isMeAccount: ->
|
||||||
for account in AccountStore.accounts()
|
for account in AccountStore.accounts()
|
||||||
if Utils.emailIsEquivalent(@email, account.emailAddress)
|
if Utils.emailIsEquivalent(@email, account.emailAddress)
|
||||||
return true
|
return account
|
||||||
|
|
||||||
for alias in account.aliases
|
for alias in account.aliases
|
||||||
if Utils.emailIsEquivalent(@email, Contact.fromString(alias).email)
|
if Utils.emailIsEquivalent(@email, Contact.fromString(alias).email)
|
||||||
return true
|
return account
|
||||||
|
|
||||||
return false
|
return null
|
||||||
|
|
||||||
|
isMePhrase: ->
|
||||||
|
account = @isMeAccount()
|
||||||
|
return null unless account
|
||||||
|
|
||||||
|
FocusedPerspectiveStore ?= require '../stores/focused-perspective-store'
|
||||||
|
if account and FocusedPerspectiveStore.current().accountIds.length > 1
|
||||||
|
return "You (#{account.label})"
|
||||||
|
return "You"
|
||||||
|
|
||||||
# Returns a {String} display name.
|
# Returns a {String} display name.
|
||||||
# - "You" if the contact is the current user
|
# - "You" if the contact is the current user
|
||||||
# - `name` if the contact has a populated name value
|
# - `name` if the contact has a populated name value
|
||||||
# - `email` in all other cases.
|
# - `email` in all other cases.
|
||||||
displayName: ->
|
displayName: ->
|
||||||
return "You" if @isMe()
|
@isMePhrase() ? @_nameParts().join(' ')
|
||||||
@_nameParts().join(' ')
|
|
||||||
|
|
||||||
displayFirstName: ->
|
displayFirstName: ->
|
||||||
return "You" if @isMe()
|
@isMePhrase() ? @firstName()
|
||||||
@firstName()
|
|
||||||
|
|
||||||
displayLastName: ->
|
displayLastName: ->
|
||||||
return "" if @isMe()
|
return "" if @isMe()
|
||||||
|
|
|
@ -192,8 +192,11 @@ class Message extends Model
|
||||||
if json.object?
|
if json.object?
|
||||||
@draft = (json.object is 'draft')
|
@draft = (json.object is 'draft')
|
||||||
|
|
||||||
for file in (@files ? [])
|
for attr in ['to', 'from', 'cc', 'bcc', 'files']
|
||||||
file.accountId = @accountId
|
values = @[attr]
|
||||||
|
continue unless values and values instanceof Array
|
||||||
|
item.accountId = @accountId for item in values
|
||||||
|
|
||||||
return @
|
return @
|
||||||
|
|
||||||
canReplyAll: ->
|
canReplyAll: ->
|
||||||
|
|
|
@ -109,6 +109,10 @@ class Thread extends Model
|
||||||
if value
|
if value
|
||||||
@categories = @constructor.attributes.categories.fromJSON(value)
|
@categories = @constructor.attributes.categories.fromJSON(value)
|
||||||
|
|
||||||
|
if @participants
|
||||||
|
for contact in @participants
|
||||||
|
contact.accountId = @accountId
|
||||||
|
|
||||||
@
|
@
|
||||||
|
|
||||||
# Public: Returns true if the thread has a {Category} with the given
|
# Public: Returns true if the thread has a {Category} with the given
|
||||||
|
|
Loading…
Reference in a new issue