cordis/client/webapp/elements/message.ts

36 lines
1.4 KiB
TypeScript

import ClientController from '../client-controller';
import { Message } from '../data-types';
import Q from '../q-module';
import createImageResourceMessage from './message-image-resource';
import createImageResourceMessageContinued from './message-image-resource-continued';
import createResourceMessage from './message-resource';
import createResourceMessageContinued from './message-resource-continued';
import createTextMessage from './message-text';
import createTextMessageContinued from './message-text-continued';
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;
}