Allow user to set display name when registering.

pull/68/head
Mikunj 7 years ago
parent 961eb53915
commit 06f79eb3fd

@ -161,7 +161,7 @@
{{ #title }} {{ #title }}
<h4>{{ title }}</h4> <h4>{{ title }}</h4>
{{ /title }} {{ /title }}
<input type='text' name='name' class='name' placeholder='Type a name' autofocus maxlength="25"> <input type='text' name='name' class='name' placeholder='Type a name' autofocus maxlength='25'>
{{ #message }} {{ #message }}
<div class='message'>{{ message }}</div> <div class='message'>{{ message }}</div>
{{ /message }} {{ /message }}
@ -594,6 +594,9 @@
<div class='step-body'> <div class='step-body'>
<div class='header'>Create your Loki Messenger Account</div> <div class='header'>Create your Loki Messenger Account</div>
<input class='form-control' type='text' id='display-name' placeholder='Display Name (optional)' autocomplete='off' spellcheck='false' maxlength='25'>
<hr>
<input class='form-control' type='text' id='mnemonic' placeholder='Mnemonic' autocomplete='off' spellcheck='false'> <input class='form-control' type='text' id='mnemonic' placeholder='Mnemonic' autocomplete='off' spellcheck='false'>
<select id='mnemonic-language'></select> <select id='mnemonic-language'></select>
@ -603,7 +606,7 @@
</div> </div>
<div id='error' class='collapse'></div> <div id='error' class='collapse'></div>
<div id=status></div> <div id=status></div>
<hr>
</div> </div>
<div class='nav'> <div class='nav'>
<a class='button' id='register' data-loading-text='Please wait...'>Register</a> <a class='button' id='register' data-loading-text='Please wait...'>Register</a>

@ -579,27 +579,15 @@
message: window.i18n('editProfileDisplayNameWarning'), message: window.i18n('editProfileDisplayNameWarning'),
nickname: displayName, nickname: displayName,
onOk: async (newName) => { onOk: async (newName) => {
// Update our profiles accordingly' await storage.setProfileName(newName);
const trimmed = newName && newName.trim();
// If we get an empty name then unset the name property
// Otherwise update it
const newProfile = profile || {};
if (_.isEmpty(trimmed)) {
delete newProfile.name;
} else {
newProfile.name = {
displayName: trimmed,
}
}
await storage.saveLocalProfile(newProfile);
appView.inboxView.trigger('updateProfile'); appView.inboxView.trigger('updateProfile');
// Update the conversation if we have it // Update the conversation if we have it
const conversation = ConversationController.get(ourNumber); const conversation = ConversationController.get(ourNumber);
if (conversation) if (conversation) {
const newProfile = storage.getLocalProfile();
conversation.setProfile(newProfile); conversation.setProfile(newProfile);
}
}, },
}) })
} }

@ -16,6 +16,25 @@
return profile; return profile;
} }
storage.setProfileName = async (newName) => {
// Update our profiles accordingly'
const trimmed = newName && newName.trim();
// If we get an empty name then unset the name property
// Otherwise update it
const profile = storage.getLocalProfile();
const newProfile = profile || {};
if (_.isEmpty(trimmed)) {
delete newProfile.name;
} else {
newProfile.name = {
displayName: trimmed,
}
}
await storage.saveLocalProfile(newProfile);
}
storage.saveLocalProfile = async (profile) => { storage.saveLocalProfile = async (profile) => {
const storedProfile = storage.get(PROFILE_ID, null); const storedProfile = storage.get(PROFILE_ID, null);

@ -1,4 +1,4 @@
/* global Whisper, $, getAccountManager, textsecure */ /* global Whisper, $, getAccountManager, textsecure, storage, ConversationController */
/* eslint-disable more/no-then */ /* eslint-disable more/no-then */
@ -47,7 +47,17 @@
this.accountManager this.accountManager
.registerSingleDevice( .registerSingleDevice(
this.$('#mnemonic').val(), this.$('#mnemonic').val(),
this.$('#mnemonic-language').val() this.$('#mnemonic-language').val(),
async (pubKey) => {
await storage.setProfileName(this.$('#display-name').val());
// Update the conversation if we have it
const conversation = ConversationController.get(pubKey);
if (conversation) {
const newProfile = storage.getLocalProfile();
conversation.setProfile(newProfile);
}
}
) )
.then(() => { .then(() => {
this.$el.trigger('openInbox'); this.$el.trigger('openInbox');

@ -49,7 +49,7 @@
requestSMSVerification(number) { requestSMSVerification(number) {
// return this.server.requestVerificationSMS(number); // return this.server.requestVerificationSMS(number);
}, },
registerSingleDevice(mnemonic, mnemonicLanguage) { registerSingleDevice(mnemonic, mnemonicLanguage, callback) {
const createAccount = this.createAccount.bind(this); const createAccount = this.createAccount.bind(this);
const clearSessionsAndPreKeys = this.clearSessionsAndPreKeys.bind(this); const clearSessionsAndPreKeys = this.clearSessionsAndPreKeys.bind(this);
const generateKeys = this.generateKeys.bind(this, 0); const generateKeys = this.generateKeys.bind(this, 0);
@ -77,7 +77,8 @@
.then(confirmKeys) .then(confirmKeys)
.then(() => { .then(() => {
const pubKeyString = StringView.arrayBufferToHex(identityKeyPair.pubKey); const pubKeyString = StringView.arrayBufferToHex(identityKeyPair.pubKey);
registrationDone(pubKeyString) registrationDone(pubKeyString);
callback(pubKeyString);
}); });
} }
) )

@ -647,6 +647,10 @@ textarea {
max-width: 35em; max-width: 35em;
} }
#display-name {
margin-bottom: 12px;
}
.inner { .inner {
display: flex; display: flex;
align-items: center; align-items: center;

Loading…
Cancel
Save