summaryrefslogtreecommitdiff
path: root/hi-ui/src/apiServer.js
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-10-05 20:32:02 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-10-05 22:47:12 -0400
commit1fb26ad31d385ddc628e1b73d6a8764981ca6885 (patch)
treeda226cfc7e054ce93bf37da943a395dee226baa6 /hi-ui/src/apiServer.js
parent8edd5625ad5dde0ef1637d5c89e9901b3ee65d73 (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/apiServer.js')
-rw-r--r--hi-ui/src/apiServer.js11
1 files changed, 5 insertions, 6 deletions
diff --git a/hi-ui/src/apiServer.js b/hi-ui/src/apiServer.js
index 6273576..f4a89a4 100644
--- a/hi-ui/src/apiServer.js
+++ b/hi-ui/src/apiServer.js
@@ -21,10 +21,6 @@ export async function logOut() {
return apiServer.post('/auth/logout', {});
}
-export async function listChannels() {
- return apiServer.get('/channels');
-}
-
export async function createChannel(name) {
return apiServer.post('/channels', { name });
}
@@ -37,8 +33,10 @@ export async function deleteMessage(messageId) {
// TODO
}
-export function subscribeToEvents() {
- const evtSource = new EventSource("/api/events");
+export function subscribeToEvents(resume_point) {
+ const eventsUrl = new URL('/api/events', window.location);
+ eventsUrl.searchParams.append('resume_point', resume_point);
+ const evtSource = new EventSource(eventsUrl.toString());
// TODO: this should process all incoming events and store them.
// TODO: eventually we'll need to handle expiring old info, so as not to use
// infinite browser memory.
@@ -58,6 +56,7 @@ export function subscribeToEvents() {
switch (data.type) {
case 'created':
+ channelsList.update((value) => value.addChannel(data.channel))
break;
case 'message':
messages.update((value) => value.addMessage(data));