summaryrefslogtreecommitdiff
path: root/ui/lib/session.svelte.js
diff options
context:
space:
mode:
Diffstat (limited to 'ui/lib/session.svelte.js')
-rw-r--r--ui/lib/session.svelte.js52
1 files changed, 49 insertions, 3 deletions
diff --git a/ui/lib/session.svelte.js b/ui/lib/session.svelte.js
index 21a391d..2dae3c4 100644
--- a/ui/lib/session.svelte.js
+++ b/ui/lib/session.svelte.js
@@ -6,16 +6,62 @@ import * as api from './apiServer.js';
import * as r from './state/remote/state.svelte.js';
import * as l from './state/local/channels.svelte.js';
import { Watchdog } from './watchdog.js';
+import { DateTime } from 'luxon';
+import { render } from '$lib/markdown.js';
+
+class Channel {
+ static fromRemote({ at, id, name }, messages, meta) {
+ const sentAt = messages
+ .filter((message) => message.channel === id)
+ .map((message) => message.at);
+ const lastEventAt = Math.max(at, ...sentAt);
+ const lastReadAt = meta.get(id)?.lastReadAt;
+
+ const hasUnreads = lastReadAt === undefined || lastEventAt > lastReadAt;
+ return new Channel({ at, id, name, hasUnreads });
+ }
+
+ constructor({ at, id, name, hasUnreads }) {
+ this.at = at;
+ this.id = id;
+ this.name = name;
+ this.hasUnreads = hasUnreads;
+ }
+}
+
+class Message {
+ static fromRemote({ id, at, channel, sender, body, renderedBody }, users) {
+ return new Message({
+ id,
+ at,
+ channel,
+ sender: users.get(sender),
+ body,
+ renderedBody
+ });
+ }
+
+ constructor({ id, at, channel, sender, body, renderedBody }) {
+ this.id = id;
+ this.at = at;
+ this.channel = channel;
+ this.sender = sender;
+ this.body = body;
+ this.renderedBody = renderedBody;
+ }
+}
class Session {
remote = $state();
local = $state();
currentUser = $derived(this.remote.currentUser);
users = $derived(this.remote.users.all);
- channels = $derived(this.remote.channels.all);
messages = $derived(
- this.remote.messages.all.map((message) =>
- message.resolve({ sender: (id) => this.users.get(id) })
+ this.remote.messages.all.map((message) => Message.fromRemote(message, this.users))
+ );
+ channels = $derived(
+ this.remote.channels.all.map((channel) =>
+ Channel.fromRemote(channel, this.messages, this.local.all)
)
);