diff --git a/client/src/js/command.js b/client/src/js/command.js index 349a2a63..1d4ae8b9 100644 --- a/client/src/js/command.js +++ b/client/src/js/command.js @@ -4,10 +4,11 @@ var messageActions = require('./actions/message'); var serverActions = require('./actions/server'); var tabActions = require('./actions/tab'); -messageActions.command.listen(function(cmd, channel, server) { - var params = cmd.slice(1).split(' '); +messageActions.command.listen(function(line, channel, server) { + var params = line.slice(1).split(' '); + var command = params[0].toLowerCase(); - switch (params[0].toLowerCase()) { + switch (command) { case 'nick': if (params[1]) { serverActions.setNick(params[1], server); diff --git a/client/src/js/irc.js b/client/src/js/irc.js index e9f1c41a..78f9e862 100644 --- a/client/src/js/irc.js +++ b/client/src/js/irc.js @@ -63,6 +63,10 @@ socket.on('channels', function(data) { channelActions.load(data); }); +serverActions.connect.listen(function(server, nick, opts) { + messageActions.inform('Connecting...', server); +}); + function withReason(message, reason) { return message + (reason ? ' (' + reason + ')' : ''); } \ No newline at end of file diff --git a/client/src/js/stores/message.js b/client/src/js/stores/message.js index 76599e49..8da33140 100644 --- a/client/src/js/stores/message.js +++ b/client/src/js/stores/message.js @@ -4,6 +4,8 @@ var _ = require('lodash'); var serverStore = require('./server'); var channelStore = require('./channel'); var actions = require('../actions/message'); +var serverActions = require('../actions/server'); +var channelActions = require('../actions/channel'); var messages = {}; @@ -30,6 +32,8 @@ function addMessage(message, dest) { var messageStore = Reflux.createStore({ init: function() { this.listenToMany(actions); + this.listenTo(serverActions.disconnect, 'disconnect'); + this.listenTo(channelActions.part, 'part'); }, send: function(message, to, server) { @@ -77,6 +81,18 @@ var messageStore = Reflux.createStore({ this.trigger(messages); }, + disconnect: function(server) { + delete messages[server]; + this.trigger(messages); + }, + + part: function(channels, server) { + _.each(channels, function(channel) { + delete messages[server][channel]; + }); + this.trigger(messages); + }, + getMessages: function(server, dest) { if (messages[server] && messages[server][dest]) { return messages[server][dest]; diff --git a/client/src/js/stores/privateChat.js b/client/src/js/stores/privateChat.js index 0f485ad7..0d481644 100644 --- a/client/src/js/stores/privateChat.js +++ b/client/src/js/stores/privateChat.js @@ -2,6 +2,7 @@ var Reflux = require('reflux'); var actions = require('../actions/privateChat'); var messageActions = require('../actions/message'); +var serverActions = require('../actions/server'); var privateChats = {}; @@ -23,6 +24,7 @@ var privateChatStore = Reflux.createStore({ init: function() { this.listenToMany(actions); this.listenTo(messageActions.add, 'messageAdded'); + this.listenTo(serverActions.disconnect, 'disconnect'); }, open: function(server, nick) { @@ -42,6 +44,11 @@ var privateChatStore = Reflux.createStore({ } }, + disconnect: function(server) { + delete privateChats[server]; + this.trigger(privateChats); + }, + getState: function() { return privateChats; } diff --git a/client/src/js/stores/selectedTab.js b/client/src/js/stores/selectedTab.js index 1f317760..a7333ddf 100644 --- a/client/src/js/stores/selectedTab.js +++ b/client/src/js/stores/selectedTab.js @@ -4,6 +4,7 @@ var _ = require('lodash'); var serverStore = require('./server'); var actions = require('../actions/tab'); var channelActions = require('../actions/channel'); +var serverActions = require('../actions/server'); var selectedTab = {}; var stored = localStorage.selectedTab; @@ -16,6 +17,9 @@ var selectedTabStore = Reflux.createStore({ init: function() { this.listenToMany(actions); this.listenTo(channelActions.part, 'part'); + this.listenTo(serverActions.disconnect, 'disconnect'); + this.listenTo(channelActions.load, 'loadChannels'); + this.listenTo(serverActions.load, 'loadServers'); }, select: function(server, channel) { @@ -32,15 +36,33 @@ var selectedTabStore = Reflux.createStore({ }, part: function(channels, server) { - var self = this; + if (server === selectedTab.server && + channels.indexOf(selectedTab.channel) !== -1) { + selectedTab.channel = null; + selectedTab.name = null; + this.trigger(selectedTab); + } + }, + + disconnect: function(server) { if (server === selectedTab.server) { - _.each(channels, function(channel) { - if (channel === selectedTab.channel) { - delete selectedTab.channel; - self.trigger(selectedTab); - return; - } - }); + selectedTab = {}; + this.trigger(selectedTab); + } + }, + + loadChannels: function(channels) { + if (selectedTab.channel && !_.find(channels, { name: selectedTab.channel })) { + selectedTab.channel = null; + selectedTab.name = null; + this.trigger(selectedTab); + } + }, + + loadServers: function(servers) { + if (selectedTab.server && !_.find(servers, { address: selectedTab.server })) { + selectedTab = {}; + this.trigger(selectedTab); } }, diff --git a/client/src/js/stores/server.js b/client/src/js/stores/server.js index 97b1f6d1..ebe980b7 100644 --- a/client/src/js/stores/server.js +++ b/client/src/js/stores/server.js @@ -11,7 +11,7 @@ var serverStore = Reflux.createStore({ this.listenToMany(actions); }, - connect: function(server, nick, username, tls, name) { + connect: function(server, nick, opts) { var i = server.indexOf(':'); if (i > 0) { server = server.slice(0, i); @@ -20,8 +20,7 @@ var serverStore = Reflux.createStore({ servers[server] = { address: server, nick: nick, - username: username, - name: name || server + name: opts.name || server }; this.trigger(servers);