From 7c3873b4494df6a44280184e54392d972e68f050 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 24 Jul 2018 12:18:10 +0100 Subject: [PATCH] fix `@room` pill href=undefined and @room parsing breaking subsequent pills Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/autocomplete/PlainWithPillsSerializer.js | 10 +++++++--- src/components/views/messages/TextualBody.js | 14 +++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/autocomplete/PlainWithPillsSerializer.js b/src/autocomplete/PlainWithPillsSerializer.js index c1194ae2e1..59cf1bde3b 100644 --- a/src/autocomplete/PlainWithPillsSerializer.js +++ b/src/autocomplete/PlainWithPillsSerializer.js @@ -64,13 +64,17 @@ class PlainWithPillsSerializer { } else if (node.type == 'emoji') { return node.data.get('emojiUnicode'); } else if (node.type == 'pill') { + const completion = node.data.get('completion'); + // over the wire the @room pill is just plaintext + if (completion === '@room') return completion; + switch (this.pillFormat) { case 'plain': - return node.data.get('completion'); + return completion; case 'md': - return `[${ node.data.get('completion') }](${ node.data.get('href') })`; + return `[${ completion }](${ node.data.get('href') })`; case 'id': - return node.data.get('completionId') || node.data.get('completion'); + return node.data.get('completionId') || completion; } } else if (node.nodes) { return node.nodes.map(this._serializeNode).join(''); diff --git a/src/components/views/messages/TextualBody.js b/src/components/views/messages/TextualBody.js index 2e5fe2aabc..17281dae09 100644 --- a/src/components/views/messages/TextualBody.js +++ b/src/components/views/messages/TextualBody.js @@ -203,7 +203,7 @@ module.exports = React.createClass({ // update the current node with one that's now taken its place node = pillContainer; } - } else if (node.nodeType == Node.TEXT_NODE) { + } else if (node.nodeType === Node.TEXT_NODE) { const Pill = sdk.getComponent('elements.Pill'); let currentTextNode = node; @@ -232,6 +232,12 @@ module.exports = React.createClass({ if (atRoomRule && pushProcessor.ruleMatchesEvent(atRoomRule, this.props.mxEvent)) { // Now replace all those nodes with Pills for (const roomNotifTextNode of roomNotifTextNodes) { + // Set the next node to be processed to the one after the node + // we're adding now, since we've just inserted nodes into the structure + // we're iterating over. + // Note we've checked roomNotifTextNodes.length > 0 so we'll do this at least once + node = roomNotifTextNode.nextSibling; + const pillContainer = document.createElement('span'); const room = MatrixClientPeg.get().getRoom(this.props.mxEvent.getRoomId()); const pill = 0 so we'll do this at least once - node = roomNotifTextNode.nextSibling; } // Nothing else to do for a text node (and we don't need to advance // the loop pointer because we did it above)