afbb46bd8c
And use that to render images in unfurls. This solves the issue of github URL unfurl images not having an image extension and then being rendered as a hyperlink by `converse-rich-text`. Instead, we know that it's supposed to be a url, so we just use `converse-image`.
34 lines
994 B
JavaScript
34 lines
994 B
JavaScript
import tpl_gif from 'templates/gif.js';
|
|
import tpl_image from 'templates/image.js';
|
|
import { CustomElement } from './element.js';
|
|
import { api } from "@converse/headless/core";
|
|
import { filterQueryParamsFromURL, isGIFURL } from '@converse/headless/utils/url.js';
|
|
|
|
|
|
export default class Image extends CustomElement {
|
|
|
|
static get properties () {
|
|
return {
|
|
'href': { type: String },
|
|
'onImgLoad': { type: Function },
|
|
'text': { type: String },
|
|
}
|
|
}
|
|
|
|
render () {
|
|
const filtered_url = filterQueryParamsFromURL(this.href);
|
|
if (isGIFURL(this.text) && this.shouldRenderMedia(this.text, 'image')) {
|
|
return tpl_gif(filtered_url);
|
|
} else {
|
|
return tpl_image({
|
|
'url': this.text,
|
|
'href': filtered_url,
|
|
'onClick': this.onImgClick,
|
|
'onLoad': this.onImgLoad
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
api.elements.define('converse-image', Image);
|