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

84 lines
1.4 KiB
JavaScript
Raw Normal View History

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) {
2016-02-04 02:35:50 +00:00
return (dispatch, getState) => 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-12-28 23:34:32 +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) {
2016-02-04 02:35:50 +00:00
return addMessages(channels.map(channel => ({
server,
to: channel,
message,
type: 'info'
})));
2015-12-28 23:34:32 +00:00
}
export function inform(message, server, channel) {
if (Array.isArray(message)) {
2016-02-04 02:35:50 +00:00
return addMessages(message.map(msg => ({
server,
to: channel,
message: msg,
type: 'info'
})));
2015-12-28 23:34:32 +00:00
}
return addMessage({
server,
to: channel,
message,
type: 'info'
});
}
export function runCommand(command, channel, server) {
return {
type: actions.COMMAND,
command,
channel,
server
};
}
2016-01-27 19:48:47 +00:00
export function raw(message, server) {
return {
type: actions.RAW,
message,
server,
socket: {
type: 'raw',
data: { message, server }
}
};
}