cordis/client/webapp/elements/message.ts

30 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-10-30 17:26:41 +00:00
import ClientController from '../client-controller';
import Elements from '../elements'
import { Message } from '../data-types';
export default function createMessage(server: ClientController, message: Message, lastMessage: Message | null): HTMLElement {
let element: HTMLElement;
if (message.hasResource()) {
if (message.isImageResource()) {
if (message.isContinued(lastMessage)) {
element = Elements.createImageResourceMessageContinued(server, message);
} else {
element = Elements.createImageResourceMessage(server, message);
}
} else {
if (message.isContinued(lastMessage)) {
element = Elements.createResourceMessageContinued(server, message);
} else {
element = Elements.createResourceMessage(server, message);
}
}
} else {
if (message.isContinued(lastMessage)) {
element = Elements.createTextMessageContinued(server, message);
} else {
element = Elements.createTextMessage(server, message);
}
}
return element;
}