import { DateTime } from 'luxon'; import { render } from '$lib/markdown.js'; class Message { static boot({ id, at, channel, sender, body }) { return new Message({ id, at: DateTime.fromISO(at), channel, sender, body, renderedBody: render(body), }); } 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; } } export class Messages { all = $state([]); static boot(messages) { const all = messages.map(Message.boot); return new Messages({ all }); } constructor({ all }) { this.all = all; } add({ id, at, channel, sender, body }) { const message = Message.boot({ id, at, channel, sender, body }); this.all.push(message); } remove(id) { const index = this.all.findIndex((message) => message.id === id); this.all.splice(index, 1); } }