Wait for server comfirmation before updating nick

This commit is contained in:
Ken-Håvard Lieng 2017-04-13 01:50:58 +02:00
parent 1739b15eaa
commit b2e3e995ce
5 changed files with 36 additions and 29 deletions

File diff suppressed because one or more lines are too long

View File

@ -27,9 +27,12 @@ export default createReducer(Map(), {
return state.delete(action.server); return state.delete(action.server);
}, },
[actions.SET_NICK](state, action) { [actions.SOCKET_NICK](state, action) {
const { server, nick } = action; const { server, old } = action;
return state.update(server, s => s.set('nick', nick)); if (!old || old === state.get(server).nick) {
return state.update(server, s => s.set('nick', action.new));
}
return state;
}, },
[actions.SOCKET_SERVERS](state, action) { [actions.SOCKET_SERVERS](state, action) {

View File

@ -191,15 +191,12 @@ func (c *Client) recv() {
} }
case ReplyWelcome: case ReplyWelcome:
c.setNick(msg.Params[0])
c.once.Do(c.ready.Done) c.once.Do(c.ready.Done)
case ErrNicknameInUse: case ErrNicknameInUse:
if c.HandleNickInUse != nil { if c.HandleNickInUse != nil {
newNick := c.HandleNickInUse(msg.Params[1]) go c.writeNick(c.HandleNickInUse(msg.Params[1]))
// Set the nick here aswell incase this happens during registration
// since there will be no NICK message to confirm it then
c.setNick(newNick)
go c.writeNick(newNick)
} }
} }

View File

@ -13,9 +13,7 @@ import (
func createNickInUseHandler(i *irc.Client, session *Session) func(string) string { func createNickInUseHandler(i *irc.Client, session *Session) func(string) string {
return func(nick string) string { return func(nick string) string {
newNick := nick + "_" newNick := nick + "_"
session.print(i.Host, "Nickname", nick, "is already in use, using", newNick, "instead") session.print(i.Host, "Nickname", nick, "is already in use, using", newNick, "instead")
go session.user.SetNick(newNick, i.Host)
return newNick return newNick
} }

View File

@ -150,6 +150,15 @@ func (i *ircHandler) quit(msg *irc.Message) {
} }
func (i *ircHandler) info(msg *irc.Message) { func (i *ircHandler) info(msg *irc.Message) {
if msg.Command == irc.ReplyWelcome {
i.session.sendJSON("nick", Nick{
Server: i.client.Host,
New: msg.Params[0],
})
go i.session.user.SetNick(msg.Params[0], i.client.Host)
}
i.session.sendJSON("pm", Chat{ i.session.sendJSON("pm", Chat{
Server: i.client.Host, Server: i.client.Host,
From: msg.Nick, From: msg.Nick,