Skip to content

Commit

Permalink
Fix #240: Prompt for nickname on conflict.
Browse files Browse the repository at this point in the history
Instead of automatically appending a suffix, the client
now prompts for a new nickname directly.
  • Loading branch information
cburschka committed May 20, 2015
1 parent d62cac9 commit a0d6b66
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
1 change: 1 addition & 0 deletions js/core/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ var strings = {
leavePage: 'Leaving this page will delete the chat history.',
macros: 'Macros:<br /><code>{macros}</code>',
motd: 'Announcement from {domain}: {raw.text}',
nickConflictResolve: 'This nickname is in user; enter another one.',
nickPrejoin: 'Your preferred nickname is now {nick}',
nickRegistered: 'Switching to registered nick {nick}.',
noUsers: 'No users are online in {room}.',
Expand Down
31 changes: 13 additions & 18 deletions js/core/xmpp.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,11 @@ var xmpp = {
},

/**
* Attempt to create a different nick by first appending, then incrementing
* a numerical suffix.
* Prompt the user to enter a different nickname.
*/
nickConflictResolve: function() {
var nick = this.nick.target;
var m = /[\d]+$/.exec(nick);
if (m) {
i = parseInt(m[0]) + 1;
nick = nick.substring(0, nick.length - m[0].length);
}
else var i = 1;
this.nick.target = nick + i;
var nick = prompt(strings.info.nickConflictResolve, this.nick.target);
if (nick && nick != this.nick.target) return this.nick.target = nick;
},

/**
Expand Down Expand Up @@ -607,13 +600,14 @@ var xmpp = {
if ($('conflict', stanza).length) {
if (room == this.room.current) {
ui.messageAddInfo(strings.error.nickConflict, {nick: nick}, 'error');
this.nick.target = this.nick.current;
return this.nick.target = this.nick.current;
}
else {
ui.messageAddInfo(strings.error.joinConflict, {nick: nick}, 'error');
this.nickConflictResolve();
ui.messageAddInfo(strings.info.rejoinNick, {nick: this.nick.target});
this.joinRoom(this.room.target, this.nick.target);
if (this.nickConflictResolve()) {
ui.messageAddInfo(strings.info.rejoinNick, {nick: this.nick.target});
return this.joinRoom(this.room.target, this.nick.target);
}
}
}
else {
Expand All @@ -625,11 +619,12 @@ var xmpp = {
ui.messageAddInfo(strings.error.badNick, {nick: nick}, 'error');
this.nick.target = this.nick.current;
}
// Cancel any join attempt:
this.room.target = this.room.current;
ui.updateRoom(this.room.current);
ui.updateFragment(this.room.current);
}

// Cancel any join attempt:
this.room.target = this.room.current;
ui.updateRoom(this.room.current);
ui.updateFragment(this.room.current);
},

/**
Expand Down

0 comments on commit a0d6b66

Please sign in to comment.