xmpp.chapril.org-conversejs/src/shared/directives/rich-text.js
JC Brand efafc2d691 Allow media to be invidually shown/rendered...
even if the global configuration is to disallow it.

* When parsing, include all media URLs, not just the ones from allowed domains.
  That makes it possible to change allowed domains on-the-fly,
  while still allowing media in individual messages to be shown manually
  (via the message actions dropdown).
* Merge `embed_audio`, `embed_video` and `show_images_inline` into `render_media`
* Create new config settings for allowable domains for images, video and audio
* Check the URL domain against a whitelist for the message actions dropdown
2021-09-21 17:08:30 +02:00

44 lines
1.1 KiB
JavaScript

import log from '@converse/headless/log.js';
import { Directive, directive } from 'lit/directive.js';
import { RichText } from 'shared/rich-text.js';
import { html } from "lit";
import { until } from 'lit/directives/until.js';
class RichTextRenderer {
constructor (text, offset, options={}) {
this.offset = offset;
this.options = options;
this.text = text;
}
async transform () {
const text = new RichText(this.text, this.offset, this.options);
try {
await text.addTemplates();
} catch (e) {
log.error(e);
}
return text.payload;
}
render () {
return html`${until(this.transform(), html`${this.text}`)}`;
}
}
class RichTextDirective extends Directive {
render (text, offset, options, callback) { // eslint-disable-line class-methods-use-this
const renderer = new RichTextRenderer(text, offset, options);
const result = renderer.render();
callback?.();
return result;
}
}
const renderRichText = directive(RichTextDirective);
export default renderRichText;