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 Reflux = require('reflux');
var _ = require('lodash');
var socket = require('../socket'); var socket = require('../socket');

View File

@ -4,7 +4,8 @@ var socket = require('../socket');
var serverActions = Reflux.createActions([ var serverActions = Reflux.createActions([
'connect', 'connect',
'disconnect' 'disconnect',
'load'
]); ]);
serverActions.connect.preEmit = function(server, nick, username) { serverActions.connect.preEmit = function(server, nick, username) {
@ -19,4 +20,8 @@ serverActions.disconnect.preEmit = function(server) {
socket.send('quit', { server: server }); socket.send('quit', { server: server });
}; };
socket.on('servers', function(data) {
serverActions.load(data);
});
module.exports = serverActions; module.exports = serverActions;

View File

@ -2,21 +2,18 @@ var React = require('react');
var Reflux = require('reflux'); var Reflux = require('reflux');
var _ = require('lodash'); var _ = require('lodash');
var serverStore = require('../stores/server');
var channelStore = require('../stores/channel'); var channelStore = require('../stores/channel');
var selectedTabStore = require('../stores/selectedTab'); var selectedTabStore = require('../stores/selectedTab');
var tabActions = require('../actions/tab'); var tabActions = require('../actions/tab');
var TabList = React.createClass({ var TabList = React.createClass({
mixins: [ mixins: [
Reflux.connect(serverStore, 'servers'),
Reflux.connect(channelStore, 'channels'), Reflux.connect(channelStore, 'channels'),
Reflux.connect(selectedTabStore, 'selectedTab') Reflux.connect(selectedTabStore, 'selectedTab')
], ],
getInitialState: function() { getInitialState: function() {
return { return {
servers: serverStore.getState(),
channels: channelStore.getState(), channels: channelStore.getState(),
selectedTab: selectedTabStore.getState() selectedTab: selectedTabStore.getState()
}; };

View File

@ -21,7 +21,7 @@ var messageStore = Reflux.createStore({
send: function(message, to, server) { send: function(message, to, server) {
addMessage({ addMessage({
server: server, server: server,
from: 'self', from: serverStore.getNick(server),
to: to, to: to,
message: message message: message
}, to); }, to);

View File

@ -1,4 +1,5 @@
var Reflux = require('reflux'); var Reflux = require('reflux');
var _ = require('lodash');
var actions = require('../actions/server'); var actions = require('../actions/server');
@ -11,13 +12,24 @@ var serverStore = Reflux.createStore({
connect: function(server, nick, username) { connect: function(server, nick, username) {
servers[server] = { servers[server] = {
server: server, address: server,
nick: nick, nick: nick,
username: username username: username
}; };
this.trigger(servers); 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() { getState: function() {
return servers; return servers;
} }

View File

@ -8,10 +8,10 @@ import (
) )
type Server struct { type Server struct {
Address string Address string `json:"address"`
Nick string Nick string `json:"nick"`
Username string Username string `json:"username"`
Realname string Realname string `json:"realname"`
} }
type Channel struct { type Channel struct {

View File

@ -52,6 +52,7 @@ func handleWS(ws *websocket.Conn) {
} }
session.sendJSON("channels", channels) session.sendJSON("channels", channels)
session.sendJSON("servers", session.user.GetServers())
} else { } else {
session = NewSession() session = NewSession()
session.user = storage.NewUser(UUID) session.user = storage.NewUser(UUID)