2020-06-24 23:50:10 +00:00
|
|
|
import { INIT } from 'state/actions';
|
|
|
|
import { getConnected, getWrapWidth } from 'state/app';
|
2020-05-03 07:05:16 +00:00
|
|
|
import { searchChannels } from 'state/channelSearch';
|
2017-06-21 06:40:28 +00:00
|
|
|
import { addMessages } from 'state/messages';
|
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) {
|
2020-06-24 23:50:10 +00:00
|
|
|
store.dispatch({
|
|
|
|
type: INIT,
|
|
|
|
settings: env.settings,
|
|
|
|
networks: env.networks,
|
|
|
|
channels: env.channels,
|
|
|
|
openDMs: env.openDMs,
|
|
|
|
users: env.users,
|
|
|
|
app: {
|
2018-12-08 10:25:08 +00:00
|
|
|
connectDefaults: env.defaults,
|
2018-12-06 12:27:53 +00:00
|
|
|
initialized: true,
|
|
|
|
hexIP: env.hexIP,
|
|
|
|
version: env.version
|
2020-06-24 23:50:10 +00:00
|
|
|
}
|
|
|
|
});
|
2018-12-06 12:27:53 +00:00
|
|
|
|
2018-12-08 10:25:08 +00:00
|
|
|
if (env.messages) {
|
|
|
|
// Wait until wrapWidth gets initialized so that height calculations
|
|
|
|
// only happen once for these messages
|
|
|
|
when(store, getWrapWidth, () => {
|
2020-06-15 08:58:51 +00:00
|
|
|
const { messages, network, to, next } = env.messages;
|
|
|
|
store.dispatch(addMessages(messages, network, to, false, next));
|
2018-12-08 10:25:08 +00:00
|
|
|
});
|
|
|
|
}
|
2020-06-24 23:50:10 +00:00
|
|
|
|
|
|
|
if (env.networks) {
|
|
|
|
when(store, getConnected, () =>
|
|
|
|
// Cache top channels for each network
|
|
|
|
env.networks.forEach(({ host }) =>
|
|
|
|
store.dispatch(searchChannels(host, ''))
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2017-05-19 05:29:44 +00:00
|
|
|
}
|
2018-11-06 10:13:32 +00:00
|
|
|
|
2018-12-08 10:25:08 +00:00
|
|
|
/* eslint-disable no-underscore-dangle */
|
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
|
|
|
}
|