mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-01 13:14:16 +08:00
fix(contact): Converge on displayName(), don't show account label in ThreadList. Fixes #1157
This commit is contained in:
parent
ea5e8e0b9e
commit
e5c6036bda
5 changed files with 32 additions and 41 deletions
|
@ -61,7 +61,7 @@ class MessageItem extends React.Component
|
|||
<div className="message-item-white-wrap">
|
||||
<div className="message-item-area">
|
||||
<div className="collapsed-from">
|
||||
{@props.message.from?[0]?.displayFirstName()}
|
||||
{@props.message.from?[0]?.displayName(compact: true)}
|
||||
</div>
|
||||
<div className="collapsed-snippet">
|
||||
{@props.message.snippet}
|
||||
|
|
|
@ -68,7 +68,7 @@ class MessageParticipants extends React.Component
|
|||
</div>
|
||||
|
||||
_shortNames: (contacts=[]) =>
|
||||
_.map(contacts, (c) -> c.displayFirstName()).join(", ")
|
||||
_.map(contacts, (c) -> c.displayName(includeAccountLabel: true, compact: true)).join(", ")
|
||||
|
||||
_fullContact: (contacts=[]) =>
|
||||
if contacts.length is 0
|
||||
|
|
|
@ -44,9 +44,9 @@ class ThreadListParticipants extends React.Component
|
|||
else
|
||||
if contact.name.length > 0
|
||||
if items.length > 1
|
||||
short = contact.displayFirstName()
|
||||
short = contact.displayName(includeAccountLabel: false, compact: true)
|
||||
else
|
||||
short = contact.displayName()
|
||||
short = contact.displayName(includeAccountLabel: false)
|
||||
else
|
||||
short = contact.email
|
||||
if idx < items.length-1 and not items[idx+1].spacer
|
||||
|
|
|
@ -68,26 +68,23 @@ describe "Contact", ->
|
|||
expect(c8.firstName()).toBe "Olivia"
|
||||
expect(c8.lastName()).toBe "Pope"
|
||||
|
||||
it "properly parses evan (Evan Morikawa)", ->
|
||||
it "should not by fancy about the contents of parenthesis (Evan Morikawa)", ->
|
||||
c8 = new Contact {name: "evan (Evan Morikawa)"}
|
||||
expect(c8.firstName()).toBe "Evan"
|
||||
expect(c8.lastName()).toBe "Morikawa"
|
||||
expect(c8.lastName()).toBe "(Evan Morikawa)"
|
||||
|
||||
it "falls back to the first component of the email if name isn't present", ->
|
||||
c1 = new Contact {name: " Evan Morikawa ", email: "evan@nylas.com"}
|
||||
expect(c1.displayName()).toBe "Evan Morikawa"
|
||||
expect(c1.displayFirstName()).toBe "Evan"
|
||||
expect(c1.displayLastName()).toBe "Morikawa"
|
||||
expect(c1.displayName(compact: true)).toBe "Evan"
|
||||
|
||||
c2 = new Contact {name: "", email: "evan@nylas.com"}
|
||||
expect(c2.displayName()).toBe "Evan"
|
||||
expect(c2.displayFirstName()).toBe "Evan"
|
||||
expect(c2.displayLastName()).toBe ""
|
||||
expect(c2.displayName(compact: true)).toBe "Evan"
|
||||
|
||||
c3 = new Contact {name: "", email: ""}
|
||||
expect(c3.displayName()).toBe ""
|
||||
expect(c3.displayFirstName()).toBe ""
|
||||
expect(c3.displayLastName()).toBe ""
|
||||
expect(c3.displayName(compact: true)).toBe ""
|
||||
|
||||
|
||||
it "properly parses names with @", ->
|
||||
|
@ -107,15 +104,6 @@ describe "Contact", ->
|
|||
expect(c3.firstName()).toBe "Nyl@s"
|
||||
expect(c3.lastName()).toBe "2000"
|
||||
|
||||
c4 = new Contact {name: " Ev@n Morikawa ", email: "evan@nylas.com"}
|
||||
expect(c4.displayName()).toBe "Ev@n Morikawa"
|
||||
expect(c4.displayFirstName()).toBe "Ev@n"
|
||||
expect(c4.displayLastName()).toBe "Morikawa"
|
||||
|
||||
c5 = new Contact {name: "ev@n (Evan Morik@wa)"}
|
||||
expect(c5.firstName()).toBe "Evan"
|
||||
expect(c5.lastName()).toBe "Morik@wa"
|
||||
|
||||
c6 = new Contact {name: "ev@nylas.com", email: "ev@nylas.com"}
|
||||
expect(c6.firstName()).toBe "Ev@nylas.com"
|
||||
expect(c6.lastName()).toBe ""
|
||||
|
@ -131,8 +119,7 @@ describe "Contact", ->
|
|||
it "should properly return `You` as the display name for the current user", ->
|
||||
c1 = new Contact {name: " Test Monkey", email: @account.emailAddress}
|
||||
expect(c1.displayName()).toBe "You"
|
||||
expect(c1.displayFirstName()).toBe "You"
|
||||
expect(c1.displayLastName()).toBe ""
|
||||
expect(c1.displayName(compact: true)).toBe "You"
|
||||
|
||||
describe "isMe", ->
|
||||
it "returns true if the contact name matches the account email address", ->
|
||||
|
|
|
@ -108,28 +108,36 @@ class Contact extends Model
|
|||
|
||||
return null
|
||||
|
||||
isMePhrase: ->
|
||||
isMePhrase: ({includeAccountLabel} = {}) ->
|
||||
account = @isMeAccount()
|
||||
return null unless account
|
||||
|
||||
FocusedPerspectiveStore ?= require '../stores/focused-perspective-store'
|
||||
if account and FocusedPerspectiveStore.current().accountIds.length > 1
|
||||
return "You (#{account.label})"
|
||||
if includeAccountLabel
|
||||
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
|
||||
# - "You" if the contact is the current user or an alias for the current user.
|
||||
# - `name` if the contact has a populated name
|
||||
# - `email` in all other cases.
|
||||
displayName: ->
|
||||
@isMePhrase() ? @_nameParts().join(' ')
|
||||
#
|
||||
# You can pass several options to customize the name:
|
||||
# - includeAccountLabel: If the contact represents the current user, include
|
||||
# the account label afer "You"
|
||||
# - compact: If the contact has a name, make the name as short as possible
|
||||
# (generally returns just the first name.)
|
||||
#
|
||||
displayName: ({includeAccountLabel, compact} = {}) ->
|
||||
compact ?= false
|
||||
includeAccountLabel ?= !compact
|
||||
|
||||
displayFirstName: ->
|
||||
@isMePhrase() ? @firstName()
|
||||
|
||||
displayLastName: ->
|
||||
return "" if @isMe()
|
||||
@lastName()
|
||||
if compact
|
||||
@isMePhrase({includeAccountLabel}) ? @firstName()
|
||||
else
|
||||
@isMePhrase({includeAccountLabel}) ? @_nameParts().join(' ')
|
||||
|
||||
firstName: ->
|
||||
articles = ['a', 'the']
|
||||
|
@ -152,10 +160,6 @@ class Contact extends Model
|
|||
# Unless there that would result in an empty string.
|
||||
name = name.split('@')[0] if name.indexOf('@') > 0
|
||||
|
||||
# Take care of phrases like "evan (Evan Morikawa)" that should be displayed
|
||||
# as the contents of the parenthesis
|
||||
name = name.split(/[()]/)[1] if name.split(/[()]/).length > 1
|
||||
|
||||
# Take care of phrases like "Mike Kaylor via LinkedIn" that should be displayed
|
||||
# as the contents before the separator word. Do not break "Olivia"
|
||||
name = name.split(/(\svia\s)/i)[0]
|
||||
|
|
Loading…
Reference in a new issue