import React from 'react'; import classnames from 'classnames'; // @ts-ignore import Mime from '../../../js/modules/types/mime'; interface Props { i18n: (key: string, values?: Array) => string; authorName: string; authorColor: string; attachments: Array; text: string; } interface QuotedAttachment { fileName: string; contentType: string; isVoiceMessage: boolean; objectUrl: string; thumbnail: { contentType: string; data: ArrayBuffer; } } function validateQuote(quote: Props): boolean { if (quote.text) { return true; } if (quote.attachments && quote.attachments.length > 0) { return true; } return false; } function getContentType(attachments: Array): string | null { if (!attachments || attachments.length === 0) { return null; } const first = attachments[0]; return first.contentType; } export class Quote extends React.Component { public renderIcon(first: QuotedAttachment) { const contentType = first.contentType; const objectUrl = first.objectUrl; if (Mime.isVideo(contentType)) { // Render play icon on top of thumbnail // We'd have to generate our own thumbnail from a local video?? return
Video
; } else if (Mime.isImage(contentType)) { if (objectUrl) { return
; } else { return
Loading Widget
} } else if (Mime.isAudio(contentType)) { // Show microphone inner in circle return
Audio
; } else { // Show file icon return
File
; } } public renderIconContainer() { const { attachments } = this.props; if (!attachments || attachments.length === 0) { return null; } const first = attachments[0]; return
{this.renderIcon(first)}
} public renderText() { const { i18n, text, attachments } = this.props; if (text) { return
{text}
; } if (!attachments || attachments.length === 0) { return null; } const contentType = getContentType(attachments); const first = attachments[0]; const fileName = first.fileName; console.log(contentType); if (Mime.isVideo(contentType)) { return
{i18n('video')}
; } else if (Mime.isImage(contentType)) { return
{i18n('photo')}
; } else if (Mime.isAudio(contentType) && first.isVoiceMessage) { return
{i18n('voiceMessage')}
; } else if (Mime.isAudio(contentType)) { console.log(first); return
{i18n('audio')}
; } return
{fileName}
; } public render() { const { authorName, authorColor } = this.props; if (!validateQuote(this.props)) { return null; } return (
{authorName}
{this.renderText()}
{this.renderIconContainer()}
); } }