cordis/client/webapp/elements/message.ts

36 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-10-30 17:26:41 +00:00
import ClientController from '../client-controller';
import { Message } from '../data-types';
import Q from '../q-module';
2021-11-07 21:57:09 +00:00
import createImageResourceMessage from './msg-img-res';
import createImageResourceMessageContinued from './msg-img-res-cont';
import createResourceMessage from './msg-res';
import createResourceMessageContinued from './msg-res-cont';
import createTextMessage from './msg-txt';
import createTextMessageContinued from './msg-txt-cont';
2021-10-30 17:26:41 +00:00
export default function createMessage(document: Document, q: Q, server: ClientController, message: Message, lastMessage: Message | null): HTMLElement {
let element: HTMLElement;
if (message.hasResource()) {
if (message.isImageResource()) {
if (message.isContinued(lastMessage)) {
element = createImageResourceMessageContinued(document, q, server, message);
} else {
element = createImageResourceMessage(document, q, server, message);
}
} else {
if (message.isContinued(lastMessage)) {
element = createResourceMessageContinued(q, server, message);
} else {
element = createResourceMessage(q, server, message);
}
}
} else {
if (message.isContinued(lastMessage)) {
element = createTextMessageContinued(q, server, message);
} else {
element = createTextMessage(q, server, message);
}
}
return element;
2021-10-30 17:26:41 +00:00
}