Implement object format to represent chat messages

Every chat text message can be split into parts such as text, newline
and links.

Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
RMidhunSuresh 2021-05-08 19:02:44 +05:30
parent 517a7516b7
commit 3c46a07a1e

View file

@ -0,0 +1,24 @@
export class MessageObjectFormat {
constructor(message = []) {
this._root = message;
}
insertText(text) {
if (text.length)
this._root.push({ type: "text", text: text });
}
insertLink(link, displayText) {
this._root.push({ type: "link", url: link, text: displayText });
}
insertNewline() {
this._root.push({ type: "newline" });
}
[Symbol.iterator]() {
return this._root.values();
}
}