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

64 lines
1.2 KiB
JavaScript
Raw Normal View History

2015-01-17 01:37:21 +00:00
var Reflux = require('reflux');
var _ = require('lodash');
2015-01-17 01:37:21 +00:00
var socket = require('../socket');
2015-01-17 01:37:21 +00:00
var messageActions = Reflux.createActions([
'send',
'add',
'broadcast'
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,
to: data.channels[0],
message: data.user + ' joined the channel',
type: 'info'
});
});
socket.on('part', function(data) {
messageActions.add({
server: data.server,
to: data.channels[0],
message: data.user + ' left the channel',
type: 'info'
});
});
socket.on('quit', function(data) {
messageActions.broadcast(data.user + ' quit', data.server);
});
socket.on('nick', function(data) {
messageActions.broadcast(data.old + ' changed nick to ' + data.new, data.server);
});
2015-01-21 23:14:28 +00:00
socket.on('motd', function(data) {
_.each(data.content.split('\n'), function(line) {
messageActions.add({
server: data.server,
to: data.server,
message: line
});
});
});
2015-01-17 01:37:21 +00:00
module.exports = messageActions;