Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Remove pills from event permalinks with text
Browse files Browse the repository at this point in the history
This removes pills from event permalinks since they hide the text associated
with the link, which can cause nonsensical messages since words have been
removed.

Fixes element-hq/element-web#16285
  • Loading branch information
jryans committed Jan 26, 2021
1 parent 71921ad commit ce4095e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 34 deletions.
6 changes: 1 addition & 5 deletions src/components/views/elements/Pill.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Copyright 2017 Vector Creations Ltd
Copyright 2018 New Vector Ltd
Copyright 2019 The Matrix.org Foundation C.I.C.
Copyright 2019, 2021 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,10 +32,6 @@ import {Action} from "../../../dispatcher/actions";
const REGEX_LOCAL_PERMALINK = /^#\/(?:user|room|group)\/(([#!@+]).*?)(?=\/|\?|$)/;

class Pill extends React.Component {
static isMessagePillUrl(url) {
return !!REGEX_LOCAL_PERMALINK.exec(url);
}

static roomNotifPos(text) {
return text.indexOf("@room");
}
Expand Down
32 changes: 3 additions & 29 deletions src/utils/pillify.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
Copyright 2019, 2020, 2021 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,33 +39,7 @@ export function pillifyLinks(nodes, mxEvent, pills) {
const shouldShowPillAvatar = SettingsStore.getValue("Pill.shouldShowPillAvatar");
let node = nodes[0];
while (node) {
let pillified = false;

if (node.tagName === "A" && node.getAttribute("href")) {
const href = node.getAttribute("href");

// If the link is a (localised) matrix.to link, replace it with a pill
const Pill = sdk.getComponent('elements.Pill');
if (Pill.isMessagePillUrl(href)) {
const pillContainer = document.createElement('span');

const pill = <Pill
url={href}
inMessage={true}
room={room}
shouldShowPillAvatar={shouldShowPillAvatar}
/>;

ReactDOM.render(pill, pillContainer);
node.parentNode.replaceChild(pillContainer, node);
pills.push(pillContainer);
// Pills within pills aren't going to go well, so move on
pillified = true;

// update the current node with one that's now taken its place
node = pillContainer;
}
} else if (
if (
node.nodeType === Node.TEXT_NODE &&
// as applying pills happens outside of react, make sure we're not doubly
// applying @room pills here, as a rerender with the same content won't touch the DOM
Expand Down Expand Up @@ -125,7 +99,7 @@ export function pillifyLinks(nodes, mxEvent, pills) {
}
}

if (node.childNodes && node.childNodes.length && !pillified) {
if (node.childNodes && node.childNodes.length) {
pillifyLinks(node.childNodes, mxEvent, pills);
}

Expand Down

0 comments on commit ce4095e

Please sign in to comment.