diff --git a/client/package.json b/client/package.json index e63be9c2..62cbebdf 100644 --- a/client/package.json +++ b/client/package.json @@ -20,7 +20,7 @@ }, "dependencies": { "lodash": "3.0.0", - "reflux": "~0.2.2", + "reflux": "0.2.4", "react-router": "~0.11.6", "react": "~0.12.2" } diff --git a/client/src/js/actions/server.js b/client/src/js/actions/server.js index ab01c586..bb987933 100644 --- a/client/src/js/actions/server.js +++ b/client/src/js/actions/server.js @@ -8,12 +8,13 @@ var serverActions = Reflux.createActions([ 'load' ]); -serverActions.connect.preEmit = function(server, nick, username, tls) { +serverActions.connect.preEmit = function(server, nick, username, tls, name) { socket.send('connect', { server: server, nick: nick, username: username, - tls: tls || false + tls: tls || false, + name: name || server }); }; diff --git a/client/src/js/app.js b/client/src/js/app.js index 6f72d899..4704f7a3 100644 --- a/client/src/js/app.js +++ b/client/src/js/app.js @@ -14,8 +14,8 @@ var nick = 'test' + Math.floor(Math.random() * 99999); socket.on('connect', function() { socket.send('uuid', uuid); - serverActions.connect('irc.freenode.net', nick, 'username', true); - serverActions.connect('irc.quakenet.org', nick, 'username'); + serverActions.connect('irc.freenode.net', nick, 'username', true, 'Freenode'); + serverActions.connect('irc.quakenet.org', nick, 'username', false, 'QuakeNet'); channelActions.join(['#stuff'], 'irc.freenode.net'); channelActions.join(['#herp'], 'irc.quakenet.org'); diff --git a/client/src/js/components/ChatTitle.jsx b/client/src/js/components/ChatTitle.jsx index 88217e8d..ddd3aaaf 100644 --- a/client/src/js/components/ChatTitle.jsx +++ b/client/src/js/components/ChatTitle.jsx @@ -19,25 +19,21 @@ var ChatTitle = React.createClass({ render: function() { var tab = this.state.selectedTab; - var title; var topic; var usercount; if (tab.channel && this.state.channels[tab.server]) { var channel = this.state.channels[tab.server][tab.channel]; - title = tab.channel if (channel) { usercount = channel.users.length; topic = channel.topic || ''; } - } else { - title = tab.server; } return (
- {title} + {tab.name} {topic}
{usercount} diff --git a/client/src/js/components/TabList.jsx b/client/src/js/components/TabList.jsx index 1ed07f22..38ba0835 100644 --- a/client/src/js/components/TabList.jsx +++ b/client/src/js/components/TabList.jsx @@ -4,6 +4,7 @@ var _ = require('lodash'); var channelStore = require('../stores/channel'); var privateChatStore = require('../stores/privateChat'); +var serverStore = require('../stores/server'); var selectedTabStore = require('../stores/selectedTab'); var tabActions = require('../actions/tab'); @@ -11,14 +12,16 @@ var TabList = React.createClass({ mixins: [ Reflux.connect(channelStore, 'channels'), Reflux.connect(privateChatStore, 'privateChats'), - Reflux.connect(selectedTabStore, 'selectedTab') + Reflux.connect(selectedTabStore, 'selectedTab'), + Reflux.connect(serverStore, 'servers') ], getInitialState: function() { return { channels: channelStore.getState(), privateChats: privateChatStore.getState(), - selectedTab: selectedTabStore.getState() + selectedTab: selectedTabStore.getState(), + servers: serverStore.getState() }; }, @@ -36,7 +39,13 @@ var TabList = React.createClass({ tabClass = ''; } - return

{name}

; + return ( +

+ {name} +

+ ); }); _.each(self.state.privateChats[address], function(chat, nick) { @@ -46,8 +55,14 @@ var TabList = React.createClass({ } else { tabClass = ''; } - - channels.push(

{nick}

); + + channels.push( +

+ {nick} +

+ ); }); if (address === selected.server && @@ -57,7 +72,13 @@ var TabList = React.createClass({ tabClass = 'tab-server'; } - channels.unshift(

{address}

); + channels.unshift( +

+ {serverStore.getName(address)} +

+ ); return channels; }); diff --git a/client/src/js/components/UserList.jsx b/client/src/js/components/UserList.jsx index 1b7e3588..b59e6aa7 100644 --- a/client/src/js/components/UserList.jsx +++ b/client/src/js/components/UserList.jsx @@ -22,20 +22,14 @@ var UserList = React.createClass({ render: function() { var users = null; var tab = this.state.selectedTab; - var style = {}; if (!tab.channel || tab.channel[0] !== '#') { style.display = 'none'; - } - - if (tab.channel && this.state.channels[tab.server]) { - var channel = this.state.channels[tab.server][tab.channel]; - if (channel) { - users = _.map(channel.users, function(user) { - return ; - }); - } + } else { + users = _.map(channelStore.getUsers(tab.server, tab.channel), function(user) { + return ; + }); } return ( diff --git a/client/src/js/stores/channel.js b/client/src/js/stores/channel.js index cb1bbd7f..c18517d2 100644 --- a/client/src/js/stores/channel.js +++ b/client/src/js/stores/channel.js @@ -186,6 +186,13 @@ var channelStore = Reflux.createStore({ return channels[server]; }, + getUsers: function(server, channel) { + if (channels[server] && channels[server][channel]) { + return channels[server][channel].users; + } + return []; + }, + getState: function() { return channels; } diff --git a/client/src/js/stores/selectedTab.js b/client/src/js/stores/selectedTab.js index db09cdd5..8cdc76bb 100644 --- a/client/src/js/stores/selectedTab.js +++ b/client/src/js/stores/selectedTab.js @@ -1,6 +1,7 @@ var Reflux = require('reflux'); var _ = require('lodash'); +var serverStore = require('./server'); var actions = require('../actions/tab'); var channelActions = require('../actions/channel'); @@ -20,6 +21,13 @@ var selectedTabStore = Reflux.createStore({ select: function(server, channel) { selectedTab.server = server; selectedTab.channel = channel; + + if (channel) { + selectedTab.name = channel; + } else { + selectedTab.name = serverStore.getName(server); + } + this.trigger(selectedTab); }, @@ -49,8 +57,8 @@ var selectedTabStore = Reflux.createStore({ } }); -selectedTabStore.listen(function(selected) { - localStorage.selectedTab = JSON.stringify(selected); +selectedTabStore.listen(function(selectedTab) { + localStorage.selectedTab = JSON.stringify(selectedTab); }); module.exports = selectedTabStore; \ No newline at end of file diff --git a/client/src/js/stores/server.js b/client/src/js/stores/server.js index a8910935..c5c4c732 100644 --- a/client/src/js/stores/server.js +++ b/client/src/js/stores/server.js @@ -10,11 +10,12 @@ var serverStore = Reflux.createStore({ this.listenToMany(actions); }, - connect: function(server, nick, username) { + connect: function(server, nick, username, tls, name) { servers[server] = { address: server, nick: nick, - username: username + username: username, + name: name || server }; this.trigger(servers); }, @@ -30,6 +31,13 @@ var serverStore = Reflux.createStore({ return servers[server].nick; }, + getName: function(server) { + if (servers[server]) { + return servers[server].name; + } + return null; + }, + getState: function() { return servers; } diff --git a/irc.go b/irc.go index 056fd727..4d9bcaf6 100644 --- a/irc.go +++ b/irc.go @@ -179,7 +179,7 @@ func (i *IRC) Writef(format string, a ...interface{}) { } func (i *IRC) write(data string) { - fmt.Fprint(i.conn, data+"\r\n") + i.conn.Write([]byte(data + "\r\n")) } func (i *IRC) writef(format string, a ...interface{}) { @@ -189,7 +189,7 @@ func (i *IRC) writef(format string, a ...interface{}) { func (i *IRC) send() { i.ready.Wait() for message := range i.out { - fmt.Fprint(i.conn, message) + i.conn.Write([]byte(message)) } } diff --git a/json_types.go b/json_types.go index 9867d091..5d947568 100644 --- a/json_types.go +++ b/json_types.go @@ -17,6 +17,7 @@ type WSResponse struct { type Connect struct { Server string `json:"server"` TLS bool `json:"tls"` + Name string `json:"name"` Nick string `json:"nick"` Username string `json:"username"` } diff --git a/main.go b/main.go index 600671f4..f3af0621 100644 --- a/main.go +++ b/main.go @@ -31,7 +31,7 @@ func main() { sessions[user.UUID] = session irc := NewIRC(server.Nick, server.Username) - irc.TLS = true + irc.TLS = server.TLS irc.Connect(server.Address) session.setIRC(irc.Host, irc) diff --git a/storage/user.go b/storage/user.go index 41a9929c..04f8ec2d 100644 --- a/storage/user.go +++ b/storage/user.go @@ -9,6 +9,8 @@ import ( type Server struct { Address string `json:"address"` + TLS bool `json:"tls"` + Name string `json:"name"` Nick string `json:"nick"` Username string `json:"username"` Realname string `json:"realname"` diff --git a/websocket_handler.go b/websocket_handler.go index 4d9ad537..3484b24f 100644 --- a/websocket_handler.go +++ b/websocket_handler.go @@ -86,6 +86,8 @@ func handleWS(ws *websocket.Conn) { session.user.AddServer(storage.Server{ Address: irc.Host, + TLS: data.TLS, + Name: data.Name, Nick: data.Nick, Username: data.Username, })