diff --git a/src/domain/session/room/timeline/MessageBodyBuilder.js b/src/domain/session/room/timeline/MessageBodyBuilder.js index 2ed8ed47..3b297cbd 100644 --- a/src/domain/session/room/timeline/MessageBodyBuilder.js +++ b/src/domain/session/room/timeline/MessageBodyBuilder.js @@ -1,9 +1,28 @@ +import { linkify } from "./linkify.js"; + export class MessageBodyBuilder { constructor(message = []) { this._root = message; } + fromText(text) { + const components = text.split("\n"); + components.slice(0, -1).forEach(t => { + linkify(t, this.insert.bind(this)); + }); + const [last] = components.slice(-1); + linkify(last, this.insert.bind(this)); + } + + insert(text, isLink) { + if (!text.length) return; + if (isLink) + this.insertLink(text, text); + else + this.insertText(text); + } + insertText(text) { if (text.length) this._root.push({ type: "text", text: text });