forked from mystiq/hydrogen-web
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:
parent
517a7516b7
commit
3c46a07a1e
1 changed files with 24 additions and 0 deletions
24
src/domain/MessageObjectFormat.js
Normal file
24
src/domain/MessageObjectFormat.js
Normal 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue