cordis/client/webapp/elements/message.ts
2021-11-21 20:47:29 -06:00

36 lines
1.3 KiB
TypeScript

import { Message } from '../data-types';
import CombinedGuild from '../guild-combined';
import Q from '../q-module';
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';
export default function createMessage(document: Document, q: Q, guild: CombinedGuild, message: Message, lastMessage: Message | null): HTMLElement {
let element: HTMLElement;
if (message.hasResource()) {
if (message.isImageResource()) {
if (message.isContinued(lastMessage)) {
element = createImageResourceMessageContinued(document, q, guild, message);
} else {
element = createImageResourceMessage(document, q, guild, message);
}
} else {
if (message.isContinued(lastMessage)) {
element = createResourceMessageContinued(q, guild, message);
} else {
element = createResourceMessage(q, guild, message);
}
}
} else {
if (message.isContinued(lastMessage)) {
element = createTextMessageContinued(q, guild, message);
} else {
element = createTextMessage(q, guild, message);
}
}
return element;
}