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