From 51ba9f5f1bcdf9739f8cc9c4ec3204645f03ae5c Mon Sep 17 00:00:00 2001 From: Nikhil Date: Sat, 24 Feb 2018 17:50:14 +0530 Subject: [PATCH 1/2] reverses token unmounting order --- .../rocketchat-ui-message/client/renderMessageBody.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/rocketchat-ui-message/client/renderMessageBody.js b/packages/rocketchat-ui-message/client/renderMessageBody.js index 1884627e2378..d4c710f9b50e 100644 --- a/packages/rocketchat-ui-message/client/renderMessageBody.js +++ b/packages/rocketchat-ui-message/client/renderMessageBody.js @@ -11,8 +11,12 @@ renderMessageBody = function(msg) { const message = RocketChat.callbacks.run('renderMessage', msg); if (message.tokens && message.tokens.length > 0) { - for (const {token, text} of message.tokens) { - message.html = message.html.replace(token, () => text); // Uses lambda so doesn't need to escape $ + let currentToken; + + // Unmounting tokens(LIFO) + while (message.tokens.length > 0) { + currentToken = message.tokens.pop(); + message.html = message.html.replace(currentToken.token, () => currentToken.text); // Uses lambda so doesn't need to escape $ } } From 11e06016e9c7ec303b887148388931768106b402 Mon Sep 17 00:00:00 2001 From: Nikhil Date: Mon, 26 Feb 2018 21:56:24 +0530 Subject: [PATCH 2/2] used array.reverse --- packages/rocketchat-ui-message/client/renderMessageBody.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/rocketchat-ui-message/client/renderMessageBody.js b/packages/rocketchat-ui-message/client/renderMessageBody.js index d4c710f9b50e..414c14561ed3 100644 --- a/packages/rocketchat-ui-message/client/renderMessageBody.js +++ b/packages/rocketchat-ui-message/client/renderMessageBody.js @@ -11,12 +11,9 @@ renderMessageBody = function(msg) { const message = RocketChat.callbacks.run('renderMessage', msg); if (message.tokens && message.tokens.length > 0) { - let currentToken; - // Unmounting tokens(LIFO) - while (message.tokens.length > 0) { - currentToken = message.tokens.pop(); - message.html = message.html.replace(currentToken.token, () => currentToken.text); // Uses lambda so doesn't need to escape $ + for (const {token, text} of message.tokens.reverse()) { + message.html = message.html.replace(token, () => text); // Uses lambda so doesn't need to escape $ } }