Show a message if user types in an invalid public key in search.

pull/26/head
Mikunj 7 years ago
parent 1ff1f50e41
commit 9d342e8951

@ -672,14 +672,19 @@
},
validateNumber() {
if (!this.id) return null;
if (this.isPrivate()) {
if (this.id.length === 33 * 2) {
// Check if it's hex
const isHex = this.id.replace(/[\s]*/g, '').match(/^[0-9a-fA-F]+$/);
if (!isHex) return 'Invalid Hex ID';
// Check if it has a valid length
if (this.id.length !== 33 * 2) {
// 33 bytes in hex
this.set({ id: this.id });
return null;
return 'Invalid ID Length';
}
return 'Invalid ID';
}
return null;
@ -1477,9 +1482,10 @@
if (avatar && avatar.path) {
return { url: getAbsoluteAttachmentPath(avatar.path), color };
} else if (this.isPrivate()) {
const symbol = this.isValid() ? '#' : '!';
return {
color,
content: title ? title.trim()[0] : '#',
content: title ? title.trim()[0] : symbol,
};
}
return { url: 'images/group_default.png', color };

@ -20,8 +20,10 @@
this.listenTo(this.model, 'change', this.render); // auto update
},
render_attributes() {
// Show the appropriate message based on model validity
const message = this.model && this.model.isValid() ? i18n('startConversation') : i18n('invalidNumberError');
return {
number: i18n('startConversation'),
number: message,
title: this.model.getNumber(),
avatar: this.model.getAvatar(),
};
@ -68,14 +70,13 @@
filterContacts() {
const query = this.$input.val().trim();
if (query.length) {
if (this.maybeNumber(query)) {
this.new_contact_view.model.set('id', query);
this.new_contact_view.render().$el.show();
this.new_contact_view.validate();
this.hideHints();
} else {
this.new_contact_view.$el.hide();
}
// Update the contact model
this.new_contact_view.model.set('id', query);
this.new_contact_view.render().$el.show();
this.new_contact_view.validate();
this.hideHints();
// NOTE: Temporarily allow `then` until we convert the entire file
// to `async` / `await`:
/* eslint-disable more/no-then */
@ -108,7 +109,6 @@
async createConversation() {
const isValidNumber = this.new_contact_view.model.isValid();
if (!isValidNumber) {
this.new_contact_view.$('.number').text(i18n('invalidNumberError'));
this.$input.focus();
return;
}
@ -155,9 +155,5 @@
this.hintView = null;
}
},
maybeNumber(number) {
return number.replace(/[\s]*/g, '').match(/^[0-9a-fA-F]+$/); // hex representation
},
});
})();

Loading…
Cancel
Save