Nick changes get handled properly by the server IRC client, user count stays hidden when the selected tab is not a channel

This commit is contained in:
khlieng 2015-02-07 00:16:51 +01:00
parent 0a47f2ae4a
commit e942924c15
5 changed files with 27 additions and 20 deletions

View File

@ -26,7 +26,7 @@ var ChatTitle = React.createClass({
<div>
<span className="chat-title">{tab.name}</span>
</div>
<span className="chat-usercount">{usercount}</span>
<span className="chat-usercount">{usercount || null}</span>
</div>
);
}

View File

@ -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');
}

22
irc.go
View File

@ -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"
}

View File

@ -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)
}

View File

@ -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()
}