diff --git a/src/components/message.js b/src/components/message.js index 2edf8dc4b..4fc24a446 100644 --- a/src/components/message.js +++ b/src/components/message.js @@ -4,6 +4,7 @@ import './message-actions.js'; import MessageVersionsModal from '../modals/message-versions.js'; import dayjs from 'dayjs'; import filesize from "filesize"; +import tpl_chat_message from '../templates/chat_message.js'; import tpl_spinner from '../templates/spinner.js'; import { CustomElement } from './element.js'; import { __ } from '@converse/headless/i18n'; @@ -14,11 +15,9 @@ import { renderAvatar } from './../templates/directives/avatar'; const { Strophe } = converse.env; const u = converse.env.utils; -const i18n_edited = __('This message has been edited'); const i18n_show = __('Show more'); const i18n_show_less = __('Show less'); const i18n_uploading = __('Uploading file:'); -const i18n_new_messages = __('New messages'); class Message extends CustomElement { @@ -124,42 +123,7 @@ class Message extends CustomElement { } renderChatMessage () { - const is_groupchat_message = (this.message_type === 'groupchat'); - return html` - ${ this.is_first_unread ? html`

${ i18n_new_messages }
` : '' } -
- - ${ this.shouldShowAvatar() ? renderAvatar(this.getAvatarData()) : '' } -
- - ${ (this.is_me_message) ? html` - - ${this.hats.map(hat => html`${hat}`)} - ` : '' } - ${ this.is_me_message ? '**' : ''}${this.username} - ${ !this.is_me_message ? this.renderAvatarByline() : '' } - ${ this.is_encrypted ? html`` : '' } - -
-
- ${ this.is_retracted ? this.renderRetraction() : this.renderMessageText() } -
- ${ (this.received && !this.is_me_message && !is_groupchat_message) ? html`` : '' } - ${ (this.edited) ? html`` : '' } - -
-
-
`; + return tpl_chat_message(this); } shouldShowAvatar () { diff --git a/src/templates/chat_message.js b/src/templates/chat_message.js new file mode 100644 index 000000000..cdacd3c85 --- /dev/null +++ b/src/templates/chat_message.js @@ -0,0 +1,46 @@ +import { html } from "lit-html"; +import { __ } from '@converse/headless/i18n'; +import { renderAvatar } from './../templates/directives/avatar'; + +const i18n_edited = __('This message has been edited'); +const i18n_new_messages = __('New messages'); + + +export default (o) => { + const is_groupchat_message = (o.message_type === 'groupchat'); + return html` + ${ o.is_first_unread ? html`

${ i18n_new_messages }
` : '' } +
+ + ${ o.shouldShowAvatar() ? renderAvatar(o.getAvatarData()) : '' } +
+ + ${ (o.is_me_message) ? html` + + ${o.hats.map(hat => html`${hat}`)} + ` : '' } + ${ o.is_me_message ? '**' : ''}${o.username} + ${ !o.is_me_message ? o.renderAvatarByline() : '' } + ${ o.is_encrypted ? html`` : '' } + +
+
+ ${ o.is_retracted ? o.renderRetraction() : o.renderMessageText() } + ${ (o.received && !o.is_me_message && !is_groupchat_message) ? html`` : '' } + ${ (o.edited) ? html`` : '' } +
+ +
+
+
`; +}