summaryrefslogtreecommitdiff
path: root/ui/lib/store
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-11-08 01:17:21 -0500
committerOwen Jacobson <owen@grimoire.ca>2024-11-08 01:22:36 -0500
commit26477b67f500a1af74e136a8ba858ca6b0f54814 (patch)
tree60ec966e3c9e3e45f2cbeb98962a37e5e9d31055 /ui/lib/store
parentd38344003092e53a84facdef1bff4fdd0ac3a017 (diff)
Stop chopping the first message off of each channel (oops).
Diffstat (limited to 'ui/lib/store')
-rw-r--r--ui/lib/store/messages.svelte.js17
1 files changed, 16 insertions, 1 deletions
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;
}