diff --git a/js/models/conversations.js b/js/models/conversations.js index 0fdc1df5..093d65b1 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -223,18 +223,28 @@ getTitle: function() { if (this.isPrivate()) { - return this.get('name') || this.id; + return this.get('name') || this.getNumber(); } else { return this.get('name') || 'Unknown group'; } }, getNumber: function() { - if (this.isPrivate()) { - return this.id; - } else { + if (!this.isPrivate()) { return ''; } + var number = this.id; + try { + var parsedNumber = libphonenumber.parse(number); + var regionCode = libphonenumber.getRegionCodeForNumber(parsedNumber); + if (regionCode === storage.get('regionCode')) { + return libphonenumber.format(parsedNumber, libphonenumber.PhoneNumberFormat.NATIONAL); + } else { + return libphonenumber.format(parsedNumber, libphonenumber.PhoneNumberFormat.INTERNATIONAL); + } + } catch (e) { + return number; + } }, isPrivate: function() { diff --git a/test/models/conversations_test.js b/test/models/conversations_test.js index 5ff7cf84..bd4f7876 100644 --- a/test/models/conversations_test.js +++ b/test/models/conversations_test.js @@ -123,7 +123,7 @@ it('has a title', function() { var convos = new Whisper.ConversationCollection(); var convo = convos.add(attributes); - assert.equal(convo.getTitle(), convo.id); + assert.equal(convo.getTitle(), '+1 808-555-5555'); convo = convos.add({type: ''}); assert.equal(convo.getTitle(), 'Unknown group'); @@ -135,7 +135,7 @@ it('returns the number', function() { var convos = new Whisper.ConversationCollection(); var convo = convos.add(attributes); - assert.equal(convo.getNumber(), convo.id); + assert.equal(convo.getNumber(), '+1 808-555-5555'); convo = convos.add({type: ''}); assert.equal(convo.getNumber(), '');