mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
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
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 New Issue
Block a user