2015-12-28 23:34:32 +00:00
|
|
|
import * as actions from '../actions';
|
2015-01-17 01:37:21 +00:00
|
|
|
|
2015-12-28 23:34:32 +00:00
|
|
|
export function sendMessage(message, to, server) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
return dispatch({
|
|
|
|
type: actions.SEND_MESSAGE,
|
|
|
|
from: getState().servers.getIn([server, 'nick']),
|
|
|
|
message,
|
|
|
|
to,
|
|
|
|
server,
|
|
|
|
time: new Date(),
|
|
|
|
socket: {
|
|
|
|
type: 'chat',
|
|
|
|
data: { message, to, server }
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
2015-01-21 02:06:34 +00:00
|
|
|
|
2015-12-28 23:34:32 +00:00
|
|
|
export function addMessage(message) {
|
|
|
|
message.time = new Date();
|
2015-01-17 01:37:21 +00:00
|
|
|
|
2015-12-28 23:34:32 +00:00
|
|
|
return {
|
|
|
|
type: actions.ADD_MESSAGE,
|
|
|
|
message
|
|
|
|
};
|
|
|
|
}
|
2015-01-17 01:37:21 +00:00
|
|
|
|
2015-12-28 23:34:32 +00:00
|
|
|
export function addMessages(messages) {
|
|
|
|
const now = new Date();
|
|
|
|
messages.forEach(message => message.time = now);
|
|
|
|
|
|
|
|
return {
|
|
|
|
type: actions.ADD_MESSAGES,
|
|
|
|
messages
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function broadcast(message, server, channels) {
|
|
|
|
return addMessages(channels.map(channel => {
|
|
|
|
return {
|
|
|
|
server,
|
|
|
|
to: channel,
|
|
|
|
message,
|
|
|
|
type: 'info'
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
export function inform(message, server, channel) {
|
|
|
|
if (Array.isArray(message)) {
|
|
|
|
return addMessages(message.map(msg => {
|
|
|
|
return {
|
|
|
|
server,
|
|
|
|
to: channel,
|
|
|
|
message: msg,
|
|
|
|
type: 'info'
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
return addMessage({
|
|
|
|
server,
|
|
|
|
to: channel,
|
|
|
|
message,
|
|
|
|
type: 'info'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function runCommand(command, channel, server) {
|
|
|
|
return {
|
|
|
|
type: actions.COMMAND,
|
|
|
|
command,
|
|
|
|
channel,
|
|
|
|
server
|
|
|
|
};
|
|
|
|
}
|