dispatch/client/src/js/actions/message.js

57 lines
1016 B
JavaScript
Raw Normal View History

2015-01-17 01:37:21 +00:00
var Reflux = require('reflux');
2015-01-21 23:14:28 +00:00
var socket = require('../socket.js');
2015-01-17 01:37:21 +00:00
var messageActions = Reflux.createActions([
'send',
2015-01-21 23:14:28 +00:00
'add'
2015-01-17 01:37:21 +00:00
]);
messageActions.send.preEmit = function(message, to, server) {
2015-01-21 23:14:28 +00:00
socket.send('chat', {
server: server,
to: to,
message: message
});
2015-01-17 01:37:21 +00:00
};
2015-01-21 23:14:28 +00:00
socket.on('message', function(data) {
messageActions.add(data);
});
socket.on('pm', function(data) {
messageActions.add(data);
});
socket.on('join', function(data) {
messageActions.add({
server: data.server,
from: '',
to: data.channels[0],
message: data.user + ' joined the channel',
type: 'info'
});
});
socket.on('part', function(data) {
messageActions.add({
server: data.server,
from: '',
to: data.channels[0],
message: data.user + ' left the channel',
type: 'info'
});
});
socket.on('motd', function(data) {
_.each(data.content.split('\n'), function(line) {
messageActions.add({
server: data.server,
from: '',
to: data.server,
message: line
});
});
});
2015-01-17 01:37:21 +00:00
module.exports = messageActions;