Browse Source

Bugfix. `pretty_time` was undefined

JC Brand 4 years ago
parent
commit
b2445d36d1
2 changed files with 4 additions and 10 deletions
  1. 2 9
      src/shared/chat/message.js
  2. 2 1
      src/shared/chat/templates/message.js

+ 2 - 9
src/shared/chat/message.js

@@ -29,8 +29,6 @@ export default class Message extends CustomElement {
     }
 
     render () {
-        const format = api.settings.get('time_format');
-        this.pretty_time = dayjs(this.model.get('edited') || this.model.get('time')).format(format);
         if (this.show_spinner) {
             return tpl_spinner();
         } else if (this.model.get('file') && !this.model.get('oob_url')) {
@@ -193,7 +191,9 @@ export default class Message extends CustomElement {
     }
 
     getDerivedMessageProps () {
+        const format = api.settings.get('time_format');
         return {
+            'pretty_time': dayjs(this.model.get('edited') || this.model.get('time')).format(format),
             'has_mentions': this.hasMentions(),
             'hats': _converse.getHats(this.model),
             'is_first_unread': this.chatbox.get('first_unread_id') === this.model.get('id'),
@@ -266,13 +266,6 @@ export default class Message extends CustomElement {
         `;
     }
 
-    renderAvatarByline () {
-        return html`
-            ${ _converse.getHats(this.model).map(h => html`<span class="badge badge-secondary">${h.title}</span>`) }
-            <time timestamp="${this.model.get('edited') || this.model.get('time')}" class="chat-msg__time">${this.pretty_time}</time>
-        `;
-    }
-
     showUserModal (ev) {
         if (this.model.get('sender') === 'me') {
             _converse.xmppstatusview.showProfileModal(ev);

+ 2 - 1
src/shared/chat/templates/message.js

@@ -23,7 +23,8 @@ export default (el, o) => {
                 ${ !o.is_me_message ? html`
                     <span class="chat-msg__heading">
                         <span class="chat-msg__author"><a class="show-msg-author-modal" @click=${el.showUserModal}>${o.username}</a></span>
-                        ${ el.renderAvatarByline() }
+                        ${ o.hats.map(h => html`<span class="badge badge-secondary">${h.title}</span>`) }
+                        <time timestamp="${el.model.get('edited') || el.model.get('time')}" class="chat-msg__time">${o.pretty_time}</time>
                         ${ o.is_encrypted ? html`<span class="fa fa-lock"></span>` : '' }
                     </span>` : '' }
                 <div class="chat-msg__body chat-msg__body--${o.message_type} ${o.received ? 'chat-msg__body--received' : '' } ${o.is_delayed ? 'chat-msg__body--delayed' : '' }">