Improved state updates when parting and quitting
This commit is contained in:
parent
99ef788906
commit
5df364a3a4
@ -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);
|
||||
|
@ -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 + ')' : '');
|
||||
}
|
@ -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];
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user