import 'shared/components/image.js'; import { getURI, isGIFURL, isDomainAllowed } from '@converse/headless/utils/url.js'; import { html } from 'lit'; function isValidURL (url) { // We don't consider relative URLs as valid return !!getURI(url).host(); } function isValidImage (image) { return image && isDomainAllowed(image, 'allowed_image_domains') && isValidURL(image); } const tplUrlWrapper = (o, wrapped_template) => o.url && isValidURL(o.url) && !isGIFURL(o.image) ? html`${wrapped_template(o)}` : wrapped_template(o); const tplImage = o => html``; export default o => { const show_image = isValidImage(o.image); const has_body_info = o.title || o.description || o.url; if (show_image || has_body_info) { return html`
${show_image ? tplImage(o) : ''} ${has_body_info ? html`
${o.title ? tplUrlWrapper(o, o => html`
${o.title}
`) : ''} ${o.description ? html`

` : ''} ${o.url ? html`

${getURI(o.url).domain()}

` : ''}
` : ''}
`; } else { return ''; } };