Display nicely formatted phone numbers
In conversation headers and as titles for contacts with no name. Updated tests accordingly. // FREEBIE
This commit is contained in:
parent
f2d2e08fa2
commit
0b95606eff
2 changed files with 16 additions and 6 deletions
|
@ -223,18 +223,28 @@
|
||||||
|
|
||||||
getTitle: function() {
|
getTitle: function() {
|
||||||
if (this.isPrivate()) {
|
if (this.isPrivate()) {
|
||||||
return this.get('name') || this.id;
|
return this.get('name') || this.getNumber();
|
||||||
} else {
|
} else {
|
||||||
return this.get('name') || 'Unknown group';
|
return this.get('name') || 'Unknown group';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getNumber: function() {
|
getNumber: function() {
|
||||||
if (this.isPrivate()) {
|
if (!this.isPrivate()) {
|
||||||
return this.id;
|
|
||||||
} else {
|
|
||||||
return '';
|
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() {
|
isPrivate: function() {
|
||||||
|
|
|
@ -123,7 +123,7 @@
|
||||||
it('has a title', function() {
|
it('has a title', function() {
|
||||||
var convos = new Whisper.ConversationCollection();
|
var convos = new Whisper.ConversationCollection();
|
||||||
var convo = convos.add(attributes);
|
var convo = convos.add(attributes);
|
||||||
assert.equal(convo.getTitle(), convo.id);
|
assert.equal(convo.getTitle(), '+1 808-555-5555');
|
||||||
|
|
||||||
convo = convos.add({type: ''});
|
convo = convos.add({type: ''});
|
||||||
assert.equal(convo.getTitle(), 'Unknown group');
|
assert.equal(convo.getTitle(), 'Unknown group');
|
||||||
|
@ -135,7 +135,7 @@
|
||||||
it('returns the number', function() {
|
it('returns the number', function() {
|
||||||
var convos = new Whisper.ConversationCollection();
|
var convos = new Whisper.ConversationCollection();
|
||||||
var convo = convos.add(attributes);
|
var convo = convos.add(attributes);
|
||||||
assert.equal(convo.getNumber(), convo.id);
|
assert.equal(convo.getNumber(), '+1 808-555-5555');
|
||||||
|
|
||||||
convo = convos.add({type: ''});
|
convo = convos.add({type: ''});
|
||||||
assert.equal(convo.getNumber(), '');
|
assert.equal(convo.getNumber(), '');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue