From 93d204ae60fb340bb9c3dc047e375a48b98f713e Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Thu, 7 Nov 2024 18:57:10 -0500 Subject: Fix up calls to `addMessage` inside `Messages`. --- ui/lib/store/messages.svelte.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'ui/lib/store/messages.svelte.js') diff --git a/ui/lib/store/messages.svelte.js b/ui/lib/store/messages.svelte.js index 4630a40..2442675 100644 --- a/ui/lib/store/messages.svelte.js +++ b/ui/lib/store/messages.svelte.js @@ -19,8 +19,7 @@ export class Messages { } else { let lastMessage = currentRun.messages.slice(-1)[0]; let newRun = - currentRun.sender !== sender - || parsedAt - lastMessage.at > RUN_COALESCE_MAX_INTERVAL; + currentRun.sender !== sender || parsedAt - lastMessage.at > RUN_COALESCE_MAX_INTERVAL; if (newRun) { currentRun = { sender, messages: [message] }; @@ -36,7 +35,7 @@ export class Messages { setMessages(messages) { this.channels = {}; for (let { channel, id, at, sender, body } of messages) { - this.addMessage(channel, id, at, sender, body); + this.addMessage(channel, id, { at, sender, body }); } return this; } -- cgit v1.2.3 From 26477b67f500a1af74e136a8ba858ca6b0f54814 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Fri, 8 Nov 2024 01:17:21 -0500 Subject: Stop chopping the first message off of each channel (oops). --- ui/lib/store/messages.svelte.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'ui/lib/store/messages.svelte.js') diff --git a/ui/lib/store/messages.svelte.js b/ui/lib/store/messages.svelte.js index 2442675..c0db71b 100644 --- a/ui/lib/store/messages.svelte.js +++ b/ui/lib/store/messages.svelte.js @@ -11,7 +11,20 @@ export class Messages { let parsedAt = new Date(at); const message = { id, at: parsedAt, body }; - let runs = (this.channels[channel] ||= []); + // You might be thinking, can't this be + // + // let runs = (this.channels[channel] ||= []); + // + // Let me tell you, I thought that too. Javascript's semantics allow it. It + // didn't work - the first message in each channel was getting lost as the + // update to `this.channels` wasn't actually happening. I suspect this is + // due to the implementation of Svelte's `$state` rune, but I don't know it + // for sure. + // + // In any case, splitting the read and write up like this has the same + // semantics, and _works_. (This time, for sure!) + let runs = this.channels[channel] || []; + let currentRun = runs.slice(-1)[0]; if (currentRun === undefined) { currentRun = { sender, messages: [message] }; @@ -29,6 +42,8 @@ export class Messages { } } + this.channels[channel] = runs; + return this; } -- cgit v1.2.3