diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-10-05 20:32:02 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-10-05 22:47:12 -0400 |
| commit | 1fb26ad31d385ddc628e1b73d6a8764981ca6885 (patch) | |
| tree | da226cfc7e054ce93bf37da943a395dee226baa6 /hi-ui/src/routes | |
| parent | 8edd5625ad5dde0ef1637d5c89e9901b3ee65d73 (diff) | |
Use `/api/boot` to bootstrap the client.
The client now takes an initial snapshot from the response to `/api/boot`, then picks up the event stream at the immediately-successive event to the moment the snapshot was taken.
This commit removes the following unused endpoints:
* `/api/channels` (GET)
* `/api/channels/:channel/messages` (GET)
The information therein is now part of the boot response. We can always add 'em back, but I wanted to clear the deck for designing something more capable, for dealing with client needs.
Diffstat (limited to 'hi-ui/src/routes')
| -rw-r--r-- | hi-ui/src/routes/+page.svelte | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/hi-ui/src/routes/+page.svelte b/hi-ui/src/routes/+page.svelte index 66b4f8d..1a61b3e 100644 --- a/hi-ui/src/routes/+page.svelte +++ b/hi-ui/src/routes/+page.svelte @@ -2,7 +2,7 @@ import { onMount } from 'svelte'; import { boot, subscribeToEvents } from '../apiServer'; - import { currentUser } from '../store'; + import { currentUser, channelsList, messages } from '../store'; import ActiveChannel from '../lib/ActiveChannel.svelte'; import ChannelList from '../lib/ChannelList.svelte'; @@ -18,16 +18,29 @@ user = value; }); + function onBooted(boot) { + currentUser.update(() => ({ + id: boot.login.id, + username: boot.login.name, + })); + let channels = boot.channels.map((channel) => ({ + id: channel.id, + name: channel.name, + })); + channelsList.update((value) => value.setChannels(channels)); + let bootMessages = boot.channels.map((channel) => [channel.id, channel.messages]); + for (let [channel, channelMessages] of bootMessages) { + messages.update((value) => value.addMessages(channel, channelMessages)); + } + } + onMount(async () => { try { let response = await boot(); switch (response.status) { case 200: - currentUser.update(() => ({ - username: response.data.login.name, - id: response.data.login.id, - })); - subscribeToEvents(); + onBooted(response.data); + subscribeToEvents(response.data.resume_point); break; case 401: currentUser.update(() => null); |
