Info about current irc connections now gets sent to the client, the correct nick shows up when sending messages

This commit is contained in:
khlieng 2015-01-22 01:03:25 +01:00
parent 83ddce0468
commit 9012e4dee5
7 changed files with 26 additions and 10 deletions

View File

@ -1,4 +1,5 @@
var Reflux = require('reflux');
var _ = require('lodash');
var socket = require('../socket');

View File

@ -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;

View File

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

View File

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

View File

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

View File

@ -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 {

View File

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