瀏覽代碼

Add option to `converse-rich-text` for /me messages

JC Brand 4 年之前
父節點
當前提交
b31eaadfab
共有 3 個文件被更改,包括 12 次插入7 次删除
  1. 1 0
      src/shared/chat/message-body.js
  2. 2 1
      src/shared/message/text.js
  3. 9 6
      src/shared/rich-text.js

+ 1 - 0
src/shared/chat/message-body.js

@@ -34,6 +34,7 @@ export default class MessageBody extends CustomElement {
             'onImgLoad': () => this.onImgLoad(),
             'render_styling': !this.model.get('is_unstyled') && api.settings.get('allow_message_styling'),
             'show_images': api.settings.get('show_images_inline'),
+            'show_me_message': true
         }
         return renderRichText(this.text, offset, mentions, options, callback);
     }

+ 2 - 1
src/shared/message/text.js

@@ -48,6 +48,7 @@ export class MessageText extends String {
      * @param { String } options.nick - The current user's nickname (only relevant if the message is in a XEP-0045 MUC)
      * @param { Boolean } options.render_styling - Whether XEP-0393 message styling should be applied to the message
      * @param { Boolean } options.show_images - Whether image URLs should be rendered as <img> tags.
+     * @param { Boolean } options.show_me_message - Whether /me messages should be rendered differently
      * @param { Function } options.onImgClick - Callback for when an inline rendered image has been clicked
      * @param { Function } options.onImgLoad - Callback for when an inline rendered image has been loaded
      */
@@ -269,7 +270,7 @@ export class MessageText extends String {
         await api.trigger('afterMessageBodyTransformed', this, {'Synchronous': true});
 
         this.payload = this.marshall();
-        this.trimMeMessage();
+        this.options.show_me_message && this.trimMeMessage();
         this.payload = this.payload.map(item => isString(item) ? item : item.template);
     }
 

+ 9 - 6
src/shared/rich-text.js

@@ -6,14 +6,15 @@ export default class RichText extends CustomElement {
 
     static get properties () {
         return {
-            text: { type: String },
-            offset: { type: Number },
             mentions: { type: Array },
             nick: { type: String },
+            offset: { type: Number },
+            onImgClick: { type: Function },
+            onImgLoad: { type: Function },
             render_styling: { type: Boolean },
             show_images: { type: Boolean },
-            onImgClick: { type: Function },
-            onImgLoad: { type: Function }
+            show_me_message: { type: Boolean },
+            text: { type: String },
         }
     }
 
@@ -23,15 +24,17 @@ export default class RichText extends CustomElement {
         this.mentions = [];
         this.render_styling = false;
         this.show_images = false;
+        this.show_me_message = false;
     }
 
     render () {
         const options = {
             nick: this.nick,
-            render_styling: this.render_styling,
-            show_images: this.show_images,
             onImgClick: this.onImgClick,
             onImgLoad: this.onImgLoad,
+            render_styling: this.render_styling,
+            show_images: this.show_images,
+            show_me_message: this.show_me_message,
         }
         return renderRichText(this.text, this.offset, this.mentions, options);
     }