summaryrefslogtreecommitdiff
path: root/ui/lib/state
diff options
context:
space:
mode:
Diffstat (limited to 'ui/lib/state')
-rw-r--r--ui/lib/state/remote/state.svelte.js4
-rw-r--r--ui/lib/state/remote/users.svelte.js19
2 files changed, 19 insertions, 4 deletions
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));
}
}