Add messageActions.addAll()

This commit is contained in:
Ken-Håvard Lieng 2015-06-10 00:45:28 +02:00
parent 29c13f4f54
commit e51c9522de
4 changed files with 38 additions and 22 deletions

File diff suppressed because one or more lines are too long

View File

@ -5,6 +5,7 @@ var socket = require('../socket');
var messageActions = Reflux.createActions([
'send',
'add',
'addAll',
'broadcast',
'inform',
'command',

View File

@ -41,13 +41,13 @@ socket.on('pm', function(data) {
});
socket.on('motd', function(data) {
_.each(data.content, function(line) {
messageActions.add({
messageActions.addAll(_.map(data.content, line => {
return {
server: data.server,
to: data.server,
message: line
});
});
};
}));
});
socket.on('users', function(data) {

View File

@ -22,7 +22,7 @@ var Message = Immutable.Record({
lines: []
});
function addMessage(message, dest) {
function addMessage(message, dest, mutable) {
message.time = new Date();
if (message.message.indexOf('\x01ACTION') === 0) {
@ -32,7 +32,19 @@ function addMessage(message, dest) {
message.message = from + message.message.slice(7);
}
messages = messages.updateIn([message.server, dest], empty, list => list.push(new Message(message)));
if (mutable) {
mutable.updateIn([message.server, dest], empty, list => list.push(new Message(message)));
} else {
messages = messages.updateIn([message.server, dest], empty, list => list.push(new Message(message)));
}
}
function getDest(message) {
var dest = message.to || message.from;
if (message.from && message.from.indexOf('.') !== -1) {
dest = message.server;
}
return dest;
}
var messageStore = Reflux.createStore({
@ -54,15 +66,18 @@ var messageStore = Reflux.createStore({
},
add(message) {
var dest = message.to || message.from;
if (message.from && message.from.indexOf('.') !== -1) {
dest = message.server;
}
addMessage(message, dest);
addMessage(message, getDest(message));
this.trigger(messages);
},
addAll(newMessages) {
messages = messages.withMutations(mutable => {
_.each(newMessages, message => {
addMessage(message, getDest(message), mutable);
});
});
},
broadcast(message, server, user) {
channelStore.getChannels(server).forEach((channel, channelName) => {
if (!user || (user && channel.get('users').find(u => u.nick === user))) {