Create contact by number with no country code or +
Search box finds or creates a conversation given a phone number in local (to the user's region) or international format. Previously you had to enter e164 format to set up the conversation correctly. If the number is not valid, do not open the conversation. TODO: user feedback on invalid numbers. // FREEBIE
This commit is contained in:
parent
0b95606eff
commit
0b7742ecd7
2 changed files with 27 additions and 5 deletions
|
@ -57,7 +57,20 @@
|
|||
}
|
||||
|
||||
if (!attributes.tokens) {
|
||||
this.updateTokens();
|
||||
return this.updateTokens();
|
||||
}
|
||||
},
|
||||
|
||||
validateNumber: function() {
|
||||
try {
|
||||
this.id = libphonenumber.util.verifyNumber(this.id);
|
||||
} catch (ex) {
|
||||
if (ex === "Invalid country calling code") {
|
||||
var regionCode = storage.get('regionCode');
|
||||
this.id = libphonenumber.util.verifyNumber(this.id, regionCode);
|
||||
} else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -70,12 +83,13 @@
|
|||
|
||||
if (this.isPrivate()) {
|
||||
try {
|
||||
this.id = libphonenumber.util.verifyNumber(this.id);
|
||||
this.validateNumber();
|
||||
var number = libphonenumber.util.splitCountryCode(this.id);
|
||||
var international_number = '' + number.country_code + number.national_number;
|
||||
var national_number = '' + number.national_number;
|
||||
|
||||
this.set({
|
||||
id: this.id,
|
||||
e164_number: this.id,
|
||||
national_number: national_number,
|
||||
international_number: international_number
|
||||
|
|
|
@ -66,9 +66,17 @@
|
|||
},
|
||||
|
||||
createConversation: function() {
|
||||
this.$el.trigger('open', this.new_contact_view.model);
|
||||
this.initNewContact();
|
||||
this.resetTypeahead();
|
||||
var conversation = this.new_contact_view.model;
|
||||
var error = conversation.validate(conversation.attributes);
|
||||
if (!error) {
|
||||
ConversationController.findOrCreatePrivateById(
|
||||
this.new_contact_view.model.id
|
||||
).then(function(conversation) {
|
||||
this.$el.trigger('open', conversation);
|
||||
this.initNewContact();
|
||||
this.resetTypeahead();
|
||||
}.bind(this));
|
||||
}
|
||||
},
|
||||
|
||||
open: function(e, conversation) {
|
||||
|
|
Loading…
Reference in a new issue