Add messageActions.addAll()
This commit is contained in:
parent
29c13f4f54
commit
e51c9522de
File diff suppressed because one or more lines are too long
|
@ -5,6 +5,7 @@ var socket = require('../socket');
|
|||
var messageActions = Reflux.createActions([
|
||||
'send',
|
||||
'add',
|
||||
'addAll',
|
||||
'broadcast',
|
||||
'inform',
|
||||
'command',
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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))) {
|
||||
|
|
Loading…
Reference in New Issue