forked from mystiq/hydrogen-web
expect MessageBody here with parts property
and do some cleanup
This commit is contained in:
parent
054c51b82f
commit
fa64fcce2d
1 changed files with 10 additions and 10 deletions
|
@ -16,7 +16,7 @@ limitations under the License.
|
||||||
|
|
||||||
import {TemplateView} from "../../../general/TemplateView.js";
|
import {TemplateView} from "../../../general/TemplateView.js";
|
||||||
import {StaticView} from "../../../general/StaticView.js";
|
import {StaticView} from "../../../general/StaticView.js";
|
||||||
import { tag, text } from "../../../general/html.js";
|
import {tag, text} from "../../../general/html.js";
|
||||||
import {renderMessage} from "./common.js";
|
import {renderMessage} from "./common.js";
|
||||||
|
|
||||||
export class TextMessageView extends TemplateView {
|
export class TextMessageView extends TemplateView {
|
||||||
|
@ -29,19 +29,19 @@ export class TextMessageView extends TemplateView {
|
||||||
}
|
}
|
||||||
|
|
||||||
const formatFunction = {
|
const formatFunction = {
|
||||||
text: (m) => text(m.text),
|
text: textPart => text(textPart.text),
|
||||||
link: (m) => tag.a({ href: m.url, target: "_blank", rel: "noopener" }, [text(m.text)]),
|
link: linkPart => tag.a({ href: linkPart.url, target: "_blank", rel: "noopener" }, [linkPart.text]),
|
||||||
newline: () => tag.br()
|
newline: () => tag.br()
|
||||||
};
|
};
|
||||||
|
|
||||||
class BodyView extends StaticView {
|
class BodyView extends StaticView {
|
||||||
render(t, value) {
|
render(t, messageBody) {
|
||||||
const children = [];
|
const container = t.span();
|
||||||
for (const m of value) {
|
for (const part of messageBody.parts) {
|
||||||
const f = formatFunction[m.type];
|
const f = formatFunction[part.type];
|
||||||
const element = f(m);
|
const element = f(part);
|
||||||
children.push(element);
|
container.appendChild(element);
|
||||||
}
|
}
|
||||||
return t.span(children);
|
return container;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue