Don't show unfurl card if there's nothing to show
This commit is contained in:
parent
64fd0ebcf6
commit
8dd8c7d1dd
@ -127,7 +127,7 @@ export function getOpenGraphMetadata (stanza) {
|
||||
const applies_to_id = fastening.getAttribute('id');
|
||||
const meta = sizzle(`> meta[xmlns="${Strophe.NS.XHTML}"]`, fastening);
|
||||
if (meta.length) {
|
||||
return meta.reduce((acc, el) => {
|
||||
const data = meta.reduce((acc, el) => {
|
||||
const property = el.getAttribute('property');
|
||||
if (property) {
|
||||
acc[property] = decodeHTMLEntities(el.getAttribute('content') || '');
|
||||
@ -136,6 +136,10 @@ export function getOpenGraphMetadata (stanza) {
|
||||
}, {
|
||||
'ogp_for_id': applies_to_id,
|
||||
});
|
||||
|
||||
if ("og:description" in data || "og:title" in data || "og:image" in data) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {};
|
||||
|
@ -44,10 +44,10 @@ export default (o) => {
|
||||
${ o.model.get('ogp_metadata')?.map(m =>
|
||||
html`<converse-message-unfurl
|
||||
jid="${o.model.collection.chatbox?.get('jid')}"
|
||||
description="${m['og:description']}"
|
||||
title="${m['og:title']}"
|
||||
image="${m['og:image']}"
|
||||
url="${m['og:url']}"></converse-message-unfurl>`) }
|
||||
description="${m['og:description'] || ''}"
|
||||
title="${m['og:title'] || ''}"
|
||||
image="${m['og:image'] || ''}"
|
||||
url="${m['og:url'] || ''}"></converse-message-unfurl>`) }
|
||||
</div>
|
||||
</div>`;
|
||||
}
|
||||
|
@ -4,9 +4,7 @@ const u = converse.env.utils;
|
||||
|
||||
export default (o) => {
|
||||
return html`<div class="card card--unfurl">
|
||||
<a href="${o.url}" target="_blank" rel="noopener">
|
||||
<img class="card-img-top" src="${o.image}" @load=${o.onload}/>
|
||||
</a>
|
||||
${ o.image ? html`<a href="${o.url}" target="_blank" rel="noopener"><img class="card-img-top" src="${o.image}" @load=${o.onload}/></a>` : '' }
|
||||
<div class="card-body">
|
||||
<a href="${o.url}" target="_blank" rel="noopener"><h5 class="card-title">${o.title}</h5></a>
|
||||
<p class="card-text">${u.addHyperlinks(o.description)}</p>
|
||||
|
@ -19,10 +19,10 @@ export default class MessageUnfurl extends CustomElement {
|
||||
return tpl_unfurl(Object.assign({
|
||||
'onload': () => this.onImageLoad()
|
||||
}, {
|
||||
description: this.description,
|
||||
image: this.image,
|
||||
title: this.title,
|
||||
url: this.url
|
||||
description: this.description || '',
|
||||
image: this.image || '',
|
||||
title: this.title || '',
|
||||
url: this.url || ''
|
||||
}));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user