Skip to content

Commit

Permalink
Better rendering of message attachment text
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Mar 14, 2016
1 parent 6b34363 commit 0d5d13c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Template.messageAttachment.helpers

return url

parsedText: ->
renderMessageBody { msg: this.text }

showImage: ->
if Meteor.user()?.settings?.preferences?.autoImageLoad is false and this.downloadImages? is not true
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

{{#if text}}
<div class="attachment-flex-column-grow attachment-text">
{{{RocketChatMarkdown text}}}
{{{parsedText}}}
</div>
{{/if}}
</div>
Expand Down
14 changes: 1 addition & 13 deletions packages/rocketchat-ui-message/message/message.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,7 @@ Template.message.onCreated ->
# console.log JSON.stringify message
return msg.html

msg.html = msg.msg
if _.trim(msg.html) isnt ''
msg.html = _.escapeHTML msg.html

message = RocketChat.callbacks.run 'renderMessage', msg
if message.tokens?.length > 0
for token in message.tokens
token.text = token.text.replace(/([^\$])(\$[^\$])/gm, '$1$$$2')
message.html = message.html.replace token.token, token.text

# console.log JSON.stringify message
msg.html = message.html.replace /\n/gm, '<br/>'
return msg.html
return renderMessageBody msg

Template.message.onViewRendered = (context) ->
view = this
Expand Down
24 changes: 24 additions & 0 deletions packages/rocketchat-ui-message/message/renderMessageBody.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* global renderMessageBody:true */
renderMessageBody = function(msg) {
var message;

msg.html = msg.msg;

if (_.trim(msg.html) !== '') {
msg.html = _.escapeHTML(msg.html);
}

message = RocketChat.callbacks.run('renderMessage', msg);

if (message.tokens && message.tokens.length > 0) {
for (var i = 0, len = message.tokens.length; i < len; i++) {
let token = message.tokens[i];
token.text = token.text.replace(/([^\$])(\$[^\$])/gm, '$1$$$2');
message.html = message.html.replace(token.token, token.text);
}
}

msg.html = message.html.replace(/\n/gm, '<br/>');

return msg.html;
};
24 changes: 13 additions & 11 deletions packages/rocketchat-ui-message/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,22 @@ Package.onUse(function(api) {
]);

api.addFiles('message/message.html', 'client');
api.addFiles("message/messageBox.html", "client");
api.addFiles("message/messageDropdown.html", "client");
api.addFiles("message/popup/messagePopup.html", "client");
api.addFiles("message/popup/messagePopupChannel.html", "client");
api.addFiles("message/popup/messagePopupConfig.html", "client");
api.addFiles("message/popup/messagePopupEmoji.html", "client");
api.addFiles("message/popup/messagePopupSlashCommand.html", "client");
api.addFiles("message/popup/messagePopupUser.html", "client");
api.addFiles('message/messageBox.html', 'client');
api.addFiles('message/messageDropdown.html', 'client');
api.addFiles('message/popup/messagePopup.html', 'client');
api.addFiles('message/popup/messagePopupChannel.html', 'client');
api.addFiles('message/popup/messagePopupConfig.html', 'client');
api.addFiles('message/popup/messagePopupEmoji.html', 'client');
api.addFiles('message/popup/messagePopupSlashCommand.html', 'client');
api.addFiles('message/popup/messagePopupUser.html', 'client');

api.addFiles('message/message.coffee', 'client');
api.addFiles('message/messageBox.coffee', 'client');
api.addFiles("message/popup/messagePopup.coffee", "client");
api.addFiles("message/popup/messagePopupConfig.coffee", "client");
api.addFiles("message/popup/messagePopupEmoji.coffee", "client");
api.addFiles('message/popup/messagePopup.coffee', 'client');
api.addFiles('message/popup/messagePopupConfig.coffee', 'client');
api.addFiles('message/popup/messagePopupEmoji.coffee', 'client');

api.addFiles('message/renderMessageBody.js', 'client');

api.export('renderMessageBody');
});

0 comments on commit 0d5d13c

Please sign in to comment.