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> <div>
<span className="chat-title">{tab.name}</span> <span className="chat-title">{tab.name}</span>
</div> </div>
<span className="chat-usercount">{usercount}</span> <span className="chat-usercount">{usercount || null}</span>
</div> </div>
); );
} }

View File

@ -5,14 +5,10 @@ var selectedTabStore = require('../stores/selectedTab');
var tabActions = require('../actions/tab'); var tabActions = require('../actions/tab');
var TabListItem = React.createClass({ var TabListItem = React.createClass({
mixins: [ mixins: [Reflux.connect(selectedTabStore)],
Reflux.connect(selectedTabStore, 'selectedTab')
],
getInitialState: function() { getInitialState: function() {
return { return selectedTabStore.getState();
selectedTab: selectedTabStore.getState()
};
}, },
handleClick: function() { handleClick: function() {
@ -20,15 +16,14 @@ var TabListItem = React.createClass({
}, },
render: function() { render: function() {
var selected = this.state.selectedTab;
var classes = []; var classes = [];
if (!this.props.channel) { if (!this.props.channel) {
classes.push('tab-server'); classes.push('tab-server');
} }
if (this.props.server === selected.server && if (this.props.server === this.state.server &&
this.props.channel === selected.channel) { this.props.channel === this.state.channel) {
classes.push('selected'); classes.push('selected');
} }

22
irc.go
View File

@ -55,17 +55,18 @@ type Message struct {
} }
type IRC struct { type IRC struct {
conn net.Conn conn net.Conn
reader *bufio.Reader reader *bufio.Reader
out chan string out chan string
ready sync.WaitGroup ready sync.WaitGroup
nick string
nickLock sync.Mutex
Messages chan *Message Messages chan *Message
Server string Server string
Host string Host string
TLS bool TLS bool
TLSConfig *tls.Config TLSConfig *tls.Config
nick string
Username string Username string
Realname string Realname string
} }
@ -132,6 +133,10 @@ func (i *IRC) Pass(password string) {
func (i *IRC) Nick(nick string) { func (i *IRC) Nick(nick string) {
i.write("NICK " + nick) i.write("NICK " + nick)
i.nickLock.Lock()
i.nick = nick
i.nickLock.Unlock()
} }
func (i *IRC) User(username, realname string) { 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) { func (i *IRC) Write(data string) {
i.out <- data + "\r\n" 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]) channelStore.AddUser(user, irc.Host, msg.Params[0])
if user == irc.nick { if user == irc.GetNick() {
session.user.AddChannel(storage.Channel{ session.user.AddChannel(storage.Channel{
Server: irc.Host, Server: irc.Host,
Name: msg.Params[0], Name: msg.Params[0],
@ -54,7 +54,7 @@ func handleMessages(irc *IRC, session *Session) {
channelStore.RemoveUser(user, irc.Host, msg.Params[0]) channelStore.RemoveUser(user, irc.Host, msg.Params[0])
if user == irc.nick { if user == irc.GetNick() {
session.user.RemoveChannel(irc.Host, msg.Params[0]) session.user.RemoveChannel(irc.Host, msg.Params[0])
} }
@ -72,7 +72,7 @@ func handleMessages(irc *IRC, session *Session) {
} }
case PRIVMSG, NOTICE: case PRIVMSG, NOTICE:
if msg.Params[0] == irc.nick { if msg.Params[0] == irc.GetNick() {
session.sendJSON("pm", Chat{ session.sendJSON("pm", Chat{
Server: irc.Host, Server: irc.Host,
From: msg.Prefix, From: msg.Prefix,
@ -186,5 +186,5 @@ func isChannel(s string) bool {
} }
func printMessage(msg *Message, irc *IRC) { 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) json.Unmarshal(req.Request, &data)
if irc, ok := session.getIRC(data.Server); ok { 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) session.user.RemoveServer(data.Server)
irc.Quit() irc.Quit()
} }