diff --git a/client/src/js/actions/message.js b/client/src/js/actions/message.js index 3070b236..67f5ceeb 100644 --- a/client/src/js/actions/message.js +++ b/client/src/js/actions/message.js @@ -1,4 +1,5 @@ var Reflux = require('reflux'); +var _ = require('lodash'); var socket = require('../socket'); diff --git a/client/src/js/actions/server.js b/client/src/js/actions/server.js index c3ffbb5d..45afbc8b 100644 --- a/client/src/js/actions/server.js +++ b/client/src/js/actions/server.js @@ -4,7 +4,8 @@ var socket = require('../socket'); var serverActions = Reflux.createActions([ 'connect', - 'disconnect' + 'disconnect', + 'load' ]); serverActions.connect.preEmit = function(server, nick, username) { @@ -19,4 +20,8 @@ serverActions.disconnect.preEmit = function(server) { socket.send('quit', { server: server }); }; +socket.on('servers', function(data) { + serverActions.load(data); +}); + module.exports = serverActions; \ No newline at end of file diff --git a/client/src/js/components/TabList.jsx b/client/src/js/components/TabList.jsx index e4810552..80a84b40 100644 --- a/client/src/js/components/TabList.jsx +++ b/client/src/js/components/TabList.jsx @@ -2,21 +2,18 @@ var React = require('react'); var Reflux = require('reflux'); var _ = require('lodash'); -var serverStore = require('../stores/server'); var channelStore = require('../stores/channel'); var selectedTabStore = require('../stores/selectedTab'); var tabActions = require('../actions/tab'); var TabList = React.createClass({ mixins: [ - Reflux.connect(serverStore, 'servers'), Reflux.connect(channelStore, 'channels'), Reflux.connect(selectedTabStore, 'selectedTab') ], getInitialState: function() { return { - servers: serverStore.getState(), channels: channelStore.getState(), selectedTab: selectedTabStore.getState() }; diff --git a/client/src/js/stores/message.js b/client/src/js/stores/message.js index d0f51f99..f30dc1ae 100644 --- a/client/src/js/stores/message.js +++ b/client/src/js/stores/message.js @@ -21,7 +21,7 @@ var messageStore = Reflux.createStore({ send: function(message, to, server) { addMessage({ server: server, - from: 'self', + from: serverStore.getNick(server), to: to, message: message }, to); diff --git a/client/src/js/stores/server.js b/client/src/js/stores/server.js index 50cee2a5..a8910935 100644 --- a/client/src/js/stores/server.js +++ b/client/src/js/stores/server.js @@ -1,4 +1,5 @@ var Reflux = require('reflux'); +var _ = require('lodash'); var actions = require('../actions/server'); @@ -11,13 +12,24 @@ var serverStore = Reflux.createStore({ connect: function(server, nick, username) { servers[server] = { - server: server, + address: server, nick: nick, username: username }; this.trigger(servers); }, + load: function(storedServers) { + _.each(storedServers, function(server) { + servers[server.address] = server; + }); + this.trigger(servers); + }, + + getNick: function(server) { + return servers[server].nick; + }, + getState: function() { return servers; } diff --git a/storage/user.go b/storage/user.go index 2d929c8b..41a9929c 100644 --- a/storage/user.go +++ b/storage/user.go @@ -8,10 +8,10 @@ import ( ) type Server struct { - Address string - Nick string - Username string - Realname string + Address string `json:"address"` + Nick string `json:"nick"` + Username string `json:"username"` + Realname string `json:"realname"` } type Channel struct { diff --git a/websocket_handler.go b/websocket_handler.go index 1233b805..184b7b05 100644 --- a/websocket_handler.go +++ b/websocket_handler.go @@ -52,6 +52,7 @@ func handleWS(ws *websocket.Conn) { } session.sendJSON("channels", channels) + session.sendJSON("servers", session.user.GetServers()) } else { session = NewSession() session.user = storage.NewUser(UUID)