From 1a8c87b10d477ceb2f9e62c50fcfef70aa94f3bf Mon Sep 17 00:00:00 2001 From: Sumukh Sridhara Date: Mon, 21 Dec 2015 03:31:37 -0800 Subject: [PATCH] Names with @ are included in the contact name. Resolves #713 --- spec/models/contact-spec.coffee | 39 +++++++++++++++++++++++++++++++++ src/flux/models/contact.coffee | 11 +++++----- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/spec/models/contact-spec.coffee b/spec/models/contact-spec.coffee index 8d48dfe2b..fcce2fe32 100644 --- a/spec/models/contact-spec.coffee +++ b/spec/models/contact-spec.coffee @@ -85,6 +85,45 @@ describe "Contact", -> expect(c3.displayFirstName()).toBe "" expect(c3.displayLastName()).toBe "" + + it "properly parses names with @", -> + c1 = new Contact {name: "nyl@s"} + expect(c1.firstName()).toBe "Nyl@s" + expect(c1.lastName()).toBe "" + + c1 = new Contact {name: "nyl@s@n1"} + expect(c1.firstName()).toBe "Nyl@s@n1" + expect(c1.lastName()).toBe "" + + c2 = new Contact {name: "nyl@s nyl@s"} + expect(c2.firstName()).toBe "Nyl@s" + expect(c2.lastName()).toBe "Nyl@s" + + c3 = new Contact {name: "nyl@s 2000"} + 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 "" + + c7 = new Contact {name: "evan@nylas.com"} + expect(c7.firstName()).toBe "Evan@nylas.com" + expect(c7.lastName()).toBe "" + + c8 = new Contact {name: "Mike K@ylor via L@nkedIn"} + expect(c8.firstName()).toBe "Mike" + expect(c8.lastName()).toBe "K@ylor" + it "should properly return `You` as the display name for the current user", -> c1 = new Contact {name: " Test Monkey", email: AccountStore.current().emailAddress} expect(c1.displayName()).toBe "You" diff --git a/src/flux/models/contact.coffee b/src/flux/models/contact.coffee index c0b5ba7f8..eec1a36a3 100644 --- a/src/flux/models/contact.coffee +++ b/src/flux/models/contact.coffee @@ -130,7 +130,12 @@ class Contact extends Model name = @name # At this point, if the name is empty we'll use the email address - name = (@email || "") unless name && name.length + unless name && name.length + name = (@email || "") + + # If the phrase has an '@', use everything before the @ sign + # 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 @@ -140,10 +145,6 @@ class Contact extends Model # as the contents before the separator word. Do not break "Olivia" name = name.split(/(\svia\s)/i)[0] - # If the phrase has an '@', use everything before the @ sign - # Unless that would result in an empty string! - name = name.split('@')[0] if name.indexOf('@') > 0 - # Take care of whitespace name = name.trim()