feat(me): Display "Me (Account Label)" in unified inbox

This commit is contained in:
Ben Gotow 2016-01-29 09:29:25 -08:00
parent b548707671
commit 395b7b9226
5 changed files with 36 additions and 13 deletions

View file

@ -26,6 +26,8 @@ pathwatcher = require 'pathwatcher'
TaskQueue,
AccountStore,
DatabaseStore,
MailboxPerspective,
FocusedPerspectiveStore,
ComponentRegistry} = require "nylas-exports"
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`
spyOn(Config::, 'load')
spyOn(Config::, 'save')

View file

@ -20,14 +20,15 @@ describe "registeredObjectReviver / registeredObjectReplacer", ->
beforeEach ->
@testThread = new Thread
id: 'local-1'
accountId: '1'
participants: [
new Contact(id: 'local-a', name: 'Juan', email:'juan@nylas.com'),
new Contact(id: 'local-b', name: 'Ben', email:'ben@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', accountId: '1')
]
subject: 'Test 1234'
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)
expect(jsonString).toEqual(expectedString)
@ -37,7 +38,7 @@ describe "registeredObjectReviver / registeredObjectReplacer", ->
it "should re-inflate Models in places they're not explicitly declared types", ->
b = new JSONBlob({id: "local-ThreadsToProcess", json: [@testThread]})
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)
revived = JSON.parse(jsonString, Utils.registeredObjectReviver)

View file

@ -3,6 +3,7 @@ Utils = require './utils'
Attributes = require '../attributes'
RegExpUtils = require '../../regexp-utils'
AccountStore = require '../stores/account-store'
FocusedPerspectiveStore = null # Circular Dependency
_ = require 'underscore'
name_prefixes = {}
@ -94,27 +95,37 @@ 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 true
return account
for alias in account.aliases
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.
# - "You" if the contact is the current user
# - `name` if the contact has a populated name value
# - `email` in all other cases.
displayName: ->
return "You" if @isMe()
@_nameParts().join(' ')
@isMePhrase() ? @_nameParts().join(' ')
displayFirstName: ->
return "You" if @isMe()
@firstName()
@isMePhrase() ? @firstName()
displayLastName: ->
return "" if @isMe()

View file

@ -192,8 +192,11 @@ class Message extends Model
if json.object?
@draft = (json.object is 'draft')
for file in (@files ? [])
file.accountId = @accountId
for attr in ['to', 'from', 'cc', 'bcc', 'files']
values = @[attr]
continue unless values and values instanceof Array
item.accountId = @accountId for item in values
return @
canReplyAll: ->

View file

@ -109,6 +109,10 @@ class Thread extends Model
if 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