Added multiserver messaging support to the client

This commit is contained in:
khlieng 2015-01-22 01:26:23 +01:00
parent 9012e4dee5
commit 0c2250b268
2 changed files with 21 additions and 13 deletions

View File

@ -31,17 +31,22 @@ var MessageBox = React.createClass({
},
render: function() {
var tab = this.state.selectedTab.channel || this.state.selectedTab.server;
var messages = _.map(this.state.messages[tab], function(message) {
var messageClass = 'message';
switch (message.type) {
case 'info':
messageClass += ' message-info';
break;
}
return <p className={messageClass}>{message.from ? message.from + ': ' : null}{message.message}</p>;
});
var tab = this.state.selectedTab;
var dest = tab.channel || tab.server;
var messages;
if (this.state.messages[tab.server] && dest) {
messages = _.map(this.state.messages[tab.server][dest], function(message) {
var messageClass = 'message';
switch (message.type) {
case 'info':
messageClass += ' message-info';
break;
}
return <p className={messageClass}>{message.from ? message.from + ': ' : null}{message.message}</p>;
});
}
return (
<div className="messagebox">{messages}</div>
);

View File

@ -6,10 +6,13 @@ var actions = require('../actions/message');
var messages = {};
function addMessage(message, dest) {
if (!(dest in messages)) {
messages[dest] = [message];
if (!(message.server in messages)) {
messages[message.server] = {};
messages[message.server][dest] = [message];
} else if (!(dest in messages[message.server])) {
messages[message.server][dest] = [message];
} else {
messages[dest].push(message);
messages[message.server][dest].push(message);
}
}