diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2025-05-08 19:40:11 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2025-05-08 19:40:11 -0400 |
| commit | 92266a13bfabf7b29f08bc85d0e8efba467167da (patch) | |
| tree | f286c25c5b5f798a6eaeba1e9a1dd5e6306530a5 /ui | |
| parent | b80b0620f7f730576a09005be0a15919925a5582 (diff) | |
Rather than exploding a user into properties inside `runs`, use a helper method.
Diffstat (limited to 'ui')
| -rw-r--r-- | ui/lib/runs.js | 11 | ||||
| -rw-r--r-- | ui/lib/state/remote/state.svelte.js | 4 | ||||
| -rw-r--r-- | ui/lib/state/remote/users.svelte.js | 19 |
3 files changed, 21 insertions, 13 deletions
diff --git a/ui/lib/runs.js b/ui/lib/runs.js index e3d4c20..de00e6a 100644 --- a/ui/lib/runs.js +++ b/ui/lib/runs.js @@ -1,4 +1,5 @@ import * as iter from './iterator.js'; +import { User } from './state/remote/users.svelte.js'; const RUN_COALESCE_MAX_INTERVAL = 10 /* min */ * 60 /* sec */ * 1000; /* ms */ @@ -21,13 +22,5 @@ function runKey(message) { } function continueRun([lastSender, lastAt], [newSender, newAt]) { - const { id: lastId, name: lastName } = lastSender; - const { id: newId, name: newName } = newSender; - if (lastId !== newId) { - return false; - } - if (lastName !== newName) { - return false; - } - return newAt - lastAt < RUN_COALESCE_MAX_INTERVAL; + return User.equal(lastSender, newSender) && newAt - lastAt < RUN_COALESCE_MAX_INTERVAL; } diff --git a/ui/lib/state/remote/state.svelte.js b/ui/lib/state/remote/state.svelte.js index 29831a0..e00d55c 100644 --- a/ui/lib/state/remote/state.svelte.js +++ b/ui/lib/state/remote/state.svelte.js @@ -1,4 +1,4 @@ -import { Users } from './users.svelte.js'; +import { User, Users } from './users.svelte.js'; import { Channels } from './channels.svelte.js'; import { Messages } from './messages.svelte.js'; @@ -10,7 +10,7 @@ export class State { static boot({ currentUser, heartbeat, users, channels, messages, resumePoint }) { return new State({ - currentUser, + currentUser: User.boot(currentUser), heartbeat, users: Users.boot(users), channels: Channels.boot(channels), diff --git a/ui/lib/state/remote/users.svelte.js b/ui/lib/state/remote/users.svelte.js index 617084f..a15d1da 100644 --- a/ui/lib/state/remote/users.svelte.js +++ b/ui/lib/state/remote/users.svelte.js @@ -1,10 +1,25 @@ import { SvelteMap } from 'svelte/reactivity'; +export class User { + static equal(a, b) { + return a.id === b.id && a.name === b.name; + } + + static boot({ id, name }) { + return new User(id, name); + } + + constructor(id, name) { + this.id = id; + this.name = name; + } +} + export class Users { all = $state(); static boot(users) { - const all = new SvelteMap(users.map((user) => [user.id, user])); + const all = new SvelteMap(users.map((user) => [user.id, User.boot(user)])); return new Users({ all }); } @@ -13,6 +28,6 @@ export class Users { } add({ id, name }) { - this.all.set(id, { id, name }); + this.all.set(id, new User(id, name)); } } |
