xmpp.chapril.org-conversejs/src/shared/chat/message-body.js

51 lines
1.7 KiB
JavaScript
Raw Normal View History

2021-03-12 09:58:17 +01:00
import 'shared/registry.js';
import ImageModal from 'modals/image.js';
import renderRichText from 'shared/directives/rich-text.js';
import { CustomElement } from 'shared/components/element.js';
import { api } from "@converse/headless/core";
2020-07-14 15:45:16 +02:00
2021-06-17 14:37:43 +02:00
import './styles/message-body.scss';
export default class MessageBody extends CustomElement {
static get properties () {
return {
model: { type: Object },
2020-07-14 15:45:16 +02:00
is_me_message: { type: Boolean },
show_images: { type: Boolean },
2021-06-17 12:31:38 +02:00
embed_videos: { type: Boolean },
2021-06-17 14:37:43 +02:00
embed_audio: { type: Boolean },
text: { type: String },
}
}
onImgClick (ev) { // eslint-disable-line class-methods-use-this
2020-07-14 15:45:16 +02:00
ev.preventDefault();
api.modal.create(ImageModal, {'src': ev.target.src}, ev).show(ev);
2020-07-14 15:45:16 +02:00
}
onImgLoad () {
this.dispatchEvent(new CustomEvent('imageLoaded', { detail: this, 'bubbles': true }));
}
render () {
const callback = () => this.model.collection?.trigger('rendered', this.model);
const offset = 0;
const mentions = this.model.get('references');
const options = {
2021-06-17 14:37:43 +02:00
'embed_audio': this.embed_audio,
'embed_videos': this.embed_videos,
'nick': this.model.collection.chatbox.get('nick'),
'onImgClick': (ev) => this.onImgClick(ev),
'onImgLoad': () => this.onImgLoad(),
'render_styling': !this.model.get('is_unstyled') && api.settings.get('allow_message_styling'),
'show_images': this.show_images,
'show_me_message': true
}
return renderRichText(this.text, offset, mentions, options, callback);
}
}
api.elements.define('converse-chat-message-body', MessageBody);