diff --git a/client/src/js/components/ChatTitle.jsx b/client/src/js/components/ChatTitle.jsx
index 737e686f..be0c9913 100644
--- a/client/src/js/components/ChatTitle.jsx
+++ b/client/src/js/components/ChatTitle.jsx
@@ -26,7 +26,7 @@ var ChatTitle = React.createClass({
{tab.name}
- {usercount}
+ {usercount || null}
);
}
diff --git a/client/src/js/components/TabListItem.jsx b/client/src/js/components/TabListItem.jsx
index 3e4f5e2d..9792f0c1 100644
--- a/client/src/js/components/TabListItem.jsx
+++ b/client/src/js/components/TabListItem.jsx
@@ -5,14 +5,10 @@ var selectedTabStore = require('../stores/selectedTab');
var tabActions = require('../actions/tab');
var TabListItem = React.createClass({
- mixins: [
- Reflux.connect(selectedTabStore, 'selectedTab')
- ],
+ mixins: [Reflux.connect(selectedTabStore)],
getInitialState: function() {
- return {
- selectedTab: selectedTabStore.getState()
- };
+ return selectedTabStore.getState();
},
handleClick: function() {
@@ -20,15 +16,14 @@ var TabListItem = React.createClass({
},
render: function() {
- var selected = this.state.selectedTab;
var classes = [];
if (!this.props.channel) {
classes.push('tab-server');
}
- if (this.props.server === selected.server &&
- this.props.channel === selected.channel) {
+ if (this.props.server === this.state.server &&
+ this.props.channel === this.state.channel) {
classes.push('selected');
}
diff --git a/irc.go b/irc.go
index 6ad1a003..53159186 100644
--- a/irc.go
+++ b/irc.go
@@ -55,17 +55,18 @@ type Message struct {
}
type IRC struct {
- conn net.Conn
- reader *bufio.Reader
- out chan string
- ready sync.WaitGroup
+ conn net.Conn
+ reader *bufio.Reader
+ out chan string
+ ready sync.WaitGroup
+ nick string
+ nickLock sync.Mutex
Messages chan *Message
Server string
Host string
TLS bool
TLSConfig *tls.Config
- nick string
Username string
Realname string
}
@@ -132,6 +133,10 @@ func (i *IRC) Pass(password string) {
func (i *IRC) Nick(nick string) {
i.write("NICK " + nick)
+
+ i.nickLock.Lock()
+ i.nick = nick
+ i.nickLock.Unlock()
}
func (i *IRC) User(username, realname string) {
@@ -170,6 +175,13 @@ func (i *IRC) Quit() {
}()
}
+func (i *IRC) GetNick() string {
+ i.nickLock.Lock()
+ defer i.nickLock.Unlock()
+
+ return i.nick
+}
+
func (i *IRC) Write(data string) {
i.out <- data + "\r\n"
}
diff --git a/message_handler.go b/message_handler.go
index 706a3c94..8dfb284a 100644
--- a/message_handler.go
+++ b/message_handler.go
@@ -33,7 +33,7 @@ func handleMessages(irc *IRC, session *Session) {
channelStore.AddUser(user, irc.Host, msg.Params[0])
- if user == irc.nick {
+ if user == irc.GetNick() {
session.user.AddChannel(storage.Channel{
Server: irc.Host,
Name: msg.Params[0],
@@ -54,7 +54,7 @@ func handleMessages(irc *IRC, session *Session) {
channelStore.RemoveUser(user, irc.Host, msg.Params[0])
- if user == irc.nick {
+ if user == irc.GetNick() {
session.user.RemoveChannel(irc.Host, msg.Params[0])
}
@@ -72,7 +72,7 @@ func handleMessages(irc *IRC, session *Session) {
}
case PRIVMSG, NOTICE:
- if msg.Params[0] == irc.nick {
+ if msg.Params[0] == irc.GetNick() {
session.sendJSON("pm", Chat{
Server: irc.Host,
From: msg.Prefix,
@@ -186,5 +186,5 @@ func isChannel(s string) bool {
}
func printMessage(msg *Message, irc *IRC) {
- log.Println(irc.nick+":", msg.Prefix, msg.Command, msg.Params, msg.Trailing)
+ log.Println(irc.GetNick()+":", msg.Prefix, msg.Command, msg.Params, msg.Trailing)
}
diff --git a/websocket_handler.go b/websocket_handler.go
index f1aff38d..2d9a90cf 100644
--- a/websocket_handler.go
+++ b/websocket_handler.go
@@ -120,7 +120,7 @@ func handleWS(ws *websocket.Conn) {
json.Unmarshal(req.Request, &data)
if irc, ok := session.getIRC(data.Server); ok {
- channelStore.RemoveUserAll(irc.nick, data.Server)
+ channelStore.RemoveUserAll(irc.GetNick(), data.Server)
session.user.RemoveServer(data.Server)
irc.Quit()
}