wip new message phone number validation
This commit is contained in:
parent
e831c649bd
commit
6e2a85ccf1
1 changed files with 23 additions and 16 deletions
|
@ -12,14 +12,23 @@ var Whisper = Whisper || {};
|
||||||
this.$el.removeClass('error');
|
this.$el.removeClass('error');
|
||||||
},
|
},
|
||||||
|
|
||||||
verifyNumber: function(item) {
|
verifyNumber: function() {
|
||||||
try {
|
try {
|
||||||
if (libphonenumber.util.verifyNumber(this.$el.val())) {
|
var val = this.$el.val();
|
||||||
this.removeError();
|
if (val[0] === '+') {
|
||||||
return;
|
// assume that the country code is specified
|
||||||
|
var number = libphonenumber.util.verifyNumber(val);
|
||||||
|
} else {
|
||||||
|
// assume that the country code should match our own
|
||||||
|
var me = textsecure.utils.unencodeNumber(textsecure.storage.getUnencrypted("number_id"))[0];
|
||||||
|
var myRegionCode = libphonenumber.util.getRegionCodeForNumber(me);
|
||||||
|
var number = libphonenumber.util.verifyNumber(val, myRegionCode);
|
||||||
}
|
}
|
||||||
} catch(ex) { console.log(ex); }
|
this.removeError();
|
||||||
this.$el.addClass('error');
|
} catch(ex) {
|
||||||
|
this.$el.addClass('error');
|
||||||
|
console.log(ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -40,16 +49,14 @@ var Whisper = Whisper || {};
|
||||||
|
|
||||||
send: function(e) {
|
send: function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var number = this.input.val();
|
var number = this.input.verifyNumber();
|
||||||
try {
|
if (number) {
|
||||||
if (libphonenumber.util.verifyNumber(number)) {
|
var thread = Whisper.Threads.findOrCreateForRecipient(number);
|
||||||
var thread = Whisper.Threads.findOrCreateForRecipient(number);
|
var message_input = this.$el.find('input.send-message');
|
||||||
var message_input = this.$el.find('input.send-message');
|
thread.sendMessage(message_input.val());
|
||||||
thread.sendMessage(message_input.val());
|
this.remove();
|
||||||
this.remove();
|
thread.trigger('render');
|
||||||
thread.trigger('render');
|
}
|
||||||
}
|
|
||||||
} catch(ex) {}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
|
|
Loading…
Reference in a new issue