mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
Transform new message format into DOM elements
Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
parent
2f883d049c
commit
bbeb0a5764
@ -21,7 +21,7 @@ import {renderMessage} from "./common.js";
|
|||||||
|
|
||||||
export class TextMessageView extends TemplateView {
|
export class TextMessageView extends TemplateView {
|
||||||
render(t, vm) {
|
render(t, vm) {
|
||||||
const bodyView = t.mapView(vm => vm.text, text => new BodyView(text));
|
const bodyView = t.mapView(vm => vm.messageFormat, messageFormat => new BodyView(messageFormat));
|
||||||
return renderMessage(t, vm,
|
return renderMessage(t, vm,
|
||||||
[t.p([bodyView, t.time({className: {hidden: !vm.date}}, vm.date + " " + vm.time)])]
|
[t.p([bodyView, t.time({className: {hidden: !vm.date}}, vm.date + " " + vm.time)])]
|
||||||
);
|
);
|
||||||
@ -29,20 +29,22 @@ export class TextMessageView extends TemplateView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class BodyView extends StaticView {
|
class BodyView extends StaticView {
|
||||||
|
|
||||||
|
get _formatFunction() {
|
||||||
|
return {
|
||||||
|
text: (param) => text(param.obj.text),
|
||||||
|
link: (param) => param.t.a({ href: param.obj.url, target: "_blank", rel: "noopener" }, [text(param.obj.text)]),
|
||||||
|
newline: (param) => param.t.br()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
render(t, value) {
|
render(t, value) {
|
||||||
const lines = (value || "").split("\n");
|
const children = [];
|
||||||
if (lines.length === 1) {
|
for (const m of value) {
|
||||||
return text(lines[0]);
|
const f = this._formatFunction[m.type];
|
||||||
|
const element = f({ obj: m, t: t });
|
||||||
|
children.push(element);
|
||||||
}
|
}
|
||||||
const elements = [];
|
return t.span(children);
|
||||||
for (const line of lines) {
|
|
||||||
if (elements.length) {
|
|
||||||
elements.push(t.br());
|
|
||||||
}
|
|
||||||
if (line.length) {
|
|
||||||
elements.push(t.span(line));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return t.span(elements);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user