2018-11-06 10:13:32 +00:00
|
|
|
/* eslint-disable no-underscore-dangle */
|
2018-12-06 12:27:53 +00:00
|
|
|
|
2017-06-21 06:40:28 +00:00
|
|
|
import { socket as socketActions } from 'state/actions';
|
2018-08-10 18:24:29 +00:00
|
|
|
import { getWrapWidth, setConnectDefaults, appSet } from 'state/app';
|
2017-06-21 06:40:28 +00:00
|
|
|
import { addMessages } from 'state/messages';
|
2018-10-15 06:56:17 +00:00
|
|
|
import { setSettings } from 'state/settings';
|
2018-04-05 19:13:32 +00:00
|
|
|
import { when } from 'utils/observe';
|
2017-05-19 05:29:44 +00:00
|
|
|
|
2018-11-06 10:13:32 +00:00
|
|
|
function loadState({ store }, env) {
|
2017-06-06 23:03:35 +00:00
|
|
|
store.dispatch(setConnectDefaults(env.defaults));
|
2018-10-15 06:56:17 +00:00
|
|
|
store.dispatch(setSettings(env.settings, true));
|
2017-05-19 05:29:44 +00:00
|
|
|
|
|
|
|
if (env.servers) {
|
|
|
|
store.dispatch({
|
2017-05-26 06:20:00 +00:00
|
|
|
type: socketActions.SERVERS,
|
2017-05-19 05:29:44 +00:00
|
|
|
data: env.servers
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (env.channels) {
|
|
|
|
store.dispatch({
|
2017-05-26 06:20:00 +00:00
|
|
|
type: socketActions.CHANNELS,
|
2017-05-19 05:29:44 +00:00
|
|
|
data: env.channels
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (env.users) {
|
|
|
|
store.dispatch({
|
2017-05-26 06:20:00 +00:00
|
|
|
type: socketActions.USERS,
|
2017-05-19 05:29:44 +00:00
|
|
|
...env.users
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:27:53 +00:00
|
|
|
store.dispatch(
|
|
|
|
appSet({
|
|
|
|
initialized: true,
|
|
|
|
hexIP: env.hexIP,
|
|
|
|
version: env.version
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2017-05-26 06:20:00 +00:00
|
|
|
// Wait until wrapWidth gets initialized so that height calculations
|
|
|
|
// only happen once for these messages
|
|
|
|
when(store, getWrapWidth, () => {
|
2017-05-19 05:29:44 +00:00
|
|
|
if (env.messages) {
|
|
|
|
const { messages, server, to, next } = env.messages;
|
|
|
|
store.dispatch(addMessages(messages, server, to, false, next));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-11-06 10:13:32 +00:00
|
|
|
|
2018-11-17 10:52:36 +00:00
|
|
|
export default async function initialState(ctx) {
|
|
|
|
const env = await window.__init__;
|
|
|
|
ctx.socket.connect();
|
|
|
|
loadState(ctx, env);
|
2018-11-06 10:13:32 +00:00
|
|
|
}
|