From 78dcc244892775185e75eec3eb62ec5426cef273 Mon Sep 17 00:00:00 2001 From: Dennis Brakhane Date: Mon, 24 Jun 2019 19:50:52 +0200 Subject: [PATCH 1/2] fix emoji size when using "marked" markdown The old logic of determing whether a message consists solely of emoji was pretty primitive: it just checked whether there are top level text nodes that contain text. This fails when using the "marked" markdown parser because it can return a

node, or a node or whatever as the first element; the old logic would conclude that the message only uses emoji and render the emojis in "big". Rewrite the logic to scan every child node, ignoring "emoji" nodes, and when there is a text node with some text, we know that the message doesn't consist solely of emojis. This approach also works with the "original" markdown parser. --- app/emoji/client/emojiParser.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/app/emoji/client/emojiParser.js b/app/emoji/client/emojiParser.js index 1d7ad1f05c99..fcdee5e3e545 100644 --- a/app/emoji/client/emojiParser.js +++ b/app/emoji/client/emojiParser.js @@ -32,7 +32,30 @@ Tracker.autorun(() => { const emojis = Array.from(checkEmojiOnly.querySelectorAll('.emoji:not(:empty), .emojione:not(:empty)')); - const emojiOnly = emojis.length && !Array.from(checkEmojiOnly.childNodes).filter((node) => node.nodeType === Node.TEXT_NODE).map((el) => el.nodeValue).join('').trim(); + const walker = document.createTreeWalker( + checkEmojiOnly, + NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT, + (node) => { + if (node.nodeType === Node.ELEMENT_NODE && ( + node.classList.contains('emojione') + || node.classList.contains('emoji') + )) { + return NodeFilter.FILTER_REJECT; + } // else + return NodeFilter.FILTER_ACCEPT; + } + ); + + let hasText = false; + + while (walker.nextNode()) { + if (walker.currentNode.nodeType === Node.TEXT_NODE && walker.currentNode.nodeValue.trim() !== '') { + hasText = true; + break; + } + } + + const emojiOnly = emojis.length && !hasText; if (emojiOnly) { for (let i = 0, len = emojis.length; i < len; i++) { From 61354d01382bda2c16e4a06ce2614b88228e5403 Mon Sep 17 00:00:00 2001 From: Tasso Evangelista Date: Thu, 11 Jul 2019 17:08:56 -0300 Subject: [PATCH 2/2] Adapt NodeFilter interface to standard --- app/emoji/client/emojiParser.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/app/emoji/client/emojiParser.js b/app/emoji/client/emojiParser.js index fcdee5e3e545..00ef84402bee 100644 --- a/app/emoji/client/emojiParser.js +++ b/app/emoji/client/emojiParser.js @@ -35,15 +35,17 @@ Tracker.autorun(() => { const walker = document.createTreeWalker( checkEmojiOnly, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT, - (node) => { - if (node.nodeType === Node.ELEMENT_NODE && ( - node.classList.contains('emojione') - || node.classList.contains('emoji') - )) { - return NodeFilter.FILTER_REJECT; - } // else - return NodeFilter.FILTER_ACCEPT; - } + { + acceptNode: (node) => { + if (node.nodeType === Node.ELEMENT_NODE && ( + node.classList.contains('emojione') + || node.classList.contains('emoji') + )) { + return NodeFilter.FILTER_REJECT; + } + return NodeFilter.FILTER_ACCEPT; + }, + }, ); let hasText = false;