Send the 25 last messages for each channel to the client on load
This commit is contained in:
parent
c840d51e16
commit
eedc687f18
26 changed files with 300 additions and 268 deletions
|
@ -1,13 +1,14 @@
|
|||
import * as actions from '../actions';
|
||||
import { findBreakpoints, messageHeight, linkify, timestamp } from '../util';
|
||||
|
||||
function initMessage(message, state) {
|
||||
message.dest = message.to || message.from || message.server;
|
||||
if (message.from && message.from.indexOf('.') !== -1) {
|
||||
message.dest = message.server;
|
||||
function initMessage(message, server, tab, state) {
|
||||
if (message.time) {
|
||||
message.time = timestamp(new Date(message.time * 1000));
|
||||
} else {
|
||||
message.time = timestamp();
|
||||
}
|
||||
|
||||
if (message.dest.charAt(0) === '#') {
|
||||
if (tab.charAt(0) === '#') {
|
||||
message.channel = true;
|
||||
}
|
||||
|
||||
|
@ -32,6 +33,13 @@ function initMessage(message, state) {
|
|||
return message;
|
||||
}
|
||||
|
||||
function getMessageTab(server, to) {
|
||||
if (!to || to.indexOf('.') !== -1) {
|
||||
return server;
|
||||
}
|
||||
return to;
|
||||
}
|
||||
|
||||
export function updateMessageHeight() {
|
||||
return (dispatch, getState) => dispatch({
|
||||
type: actions.UPDATE_MESSAGE_HEIGHT,
|
||||
|
@ -46,13 +54,12 @@ export function sendMessage(content, to, server) {
|
|||
|
||||
dispatch({
|
||||
type: actions.SEND_MESSAGE,
|
||||
server,
|
||||
tab: to,
|
||||
message: initMessage({
|
||||
from: state.servers.getIn([server, 'nick']),
|
||||
content,
|
||||
to,
|
||||
server,
|
||||
time: timestamp()
|
||||
}, state),
|
||||
content
|
||||
}, server, to, state),
|
||||
socket: {
|
||||
type: 'message',
|
||||
data: { content, to, server }
|
||||
|
@ -61,27 +68,29 @@ export function sendMessage(content, to, server) {
|
|||
};
|
||||
}
|
||||
|
||||
export function addMessage(message) {
|
||||
message.time = timestamp();
|
||||
export function addMessage(message, server, to) {
|
||||
const tab = getMessageTab(server, to);
|
||||
|
||||
return (dispatch, getState) => dispatch({
|
||||
type: actions.ADD_MESSAGE,
|
||||
message: initMessage(message, getState())
|
||||
server,
|
||||
tab,
|
||||
message: initMessage(message, server, tab, getState())
|
||||
});
|
||||
}
|
||||
|
||||
export function addMessages(messages) {
|
||||
const now = timestamp();
|
||||
export function addMessages(messages, server, to) {
|
||||
const tab = getMessageTab(server, to);
|
||||
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
|
||||
messages.forEach(message => {
|
||||
initMessage(message, state).time = now;
|
||||
});
|
||||
messages.forEach(message => initMessage(message, server, message.tab || tab, state));
|
||||
|
||||
dispatch({
|
||||
type: actions.ADD_MESSAGES,
|
||||
server,
|
||||
tab,
|
||||
messages
|
||||
});
|
||||
};
|
||||
|
@ -89,29 +98,24 @@ export function addMessages(messages) {
|
|||
|
||||
export function broadcast(message, server, channels) {
|
||||
return addMessages(channels.map(channel => ({
|
||||
server,
|
||||
to: channel,
|
||||
tab: channel,
|
||||
content: message,
|
||||
type: 'info'
|
||||
})));
|
||||
})), server);
|
||||
}
|
||||
|
||||
export function inform(message, server, channel) {
|
||||
if (Array.isArray(message)) {
|
||||
return addMessages(message.map(line => ({
|
||||
server,
|
||||
to: channel,
|
||||
content: line,
|
||||
type: 'info'
|
||||
})));
|
||||
})), server, channel);
|
||||
}
|
||||
|
||||
return addMessage({
|
||||
server,
|
||||
to: channel,
|
||||
content: message,
|
||||
type: 'info'
|
||||
});
|
||||
}, server, channel);
|
||||
}
|
||||
|
||||
export function runCommand(command, channel, server) {
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
import { push, replace } from 'react-router-redux';
|
||||
import * as actions from '../actions';
|
||||
|
||||
export function select(server, channel, pm) {
|
||||
export function select(server, name) {
|
||||
const pm = name && name.charAt(0) !== '#';
|
||||
if (pm) {
|
||||
return push(`/${server}/pm/${channel}`);
|
||||
} else if (channel) {
|
||||
return push(`/${server}/${encodeURIComponent(channel)}`);
|
||||
return push(`/${server}/pm/${name}`);
|
||||
} else if (name) {
|
||||
return push(`/${server}/${encodeURIComponent(name)}`);
|
||||
}
|
||||
|
||||
return push(`/${server}`);
|
||||
|
@ -22,7 +23,7 @@ export function updateSelection() {
|
|||
dispatch(replace('/connect'));
|
||||
} else if (history.size > 0) {
|
||||
const tab = history.last();
|
||||
dispatch(select(tab.server, tab.channel || tab.user, tab.user));
|
||||
dispatch(select(tab.server, tab.name));
|
||||
} else if (servers.has(server)) {
|
||||
dispatch(select(server));
|
||||
} else {
|
||||
|
@ -31,18 +32,10 @@ export function updateSelection() {
|
|||
};
|
||||
}
|
||||
|
||||
export function setSelectedChannel(server, channel = null) {
|
||||
export function setSelectedTab(server, name = null) {
|
||||
return {
|
||||
type: actions.SELECT_TAB,
|
||||
server,
|
||||
channel
|
||||
};
|
||||
}
|
||||
|
||||
export function setSelectedUser(server, user = null) {
|
||||
return {
|
||||
type: actions.SELECT_TAB,
|
||||
server,
|
||||
user
|
||||
name
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue