2015-01-17 01:37:21 +00:00
|
|
|
var Reflux = require('reflux');
|
2015-01-22 00:03:25 +00:00
|
|
|
var _ = require('lodash');
|
2015-01-17 01:37:21 +00:00
|
|
|
|
2015-01-21 23:32:32 +00:00
|
|
|
var socket = require('../socket');
|
2015-01-21 02:06:34 +00:00
|
|
|
|
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
|
|
|
]);
|
|
|
|
|
2015-01-21 02:06:34 +00:00
|
|
|
messageActions.send.preEmit = function(message, to, server) {
|
2015-01-21 23:14:28 +00:00
|
|
|
socket.send('chat', {
|
2015-01-21 02:06:34 +00:00
|
|
|
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;
|