diff --git a/app/javascript/flavours/glitch/components/status.js b/app/javascript/flavours/glitch/components/status.js index 06280d8d55..170efad043 100644 --- a/app/javascript/flavours/glitch/components/status.js +++ b/app/javascript/flavours/glitch/components/status.js @@ -699,7 +699,7 @@ class Status extends ImmutablePureComponent { onExpandedToggle={this.handleExpandedToggle} parseClick={parseClick} disabled={!router} - linkRewriting={settings.get('link_rewriting')} + tagLinks={settings.get('tag_misleading_links')} /> {!isCollapsed || !(muted || !settings.getIn(['collapsed', 'show_action_bar'])) ? ( { return (text === origin || text === host || text.startsWith(origin + '/') || text.startsWith(host + '/') || 'www.' + text === host || ('www.' + text).startsWith(host + '/')); } -// If `checkUrlLike` is true, consider only URL-like link texts to be misleading -const isLinkMisleading = (link, checkUrlLike = true) => { +const isLinkMisleading = (link) => { let linkTextParts = []; // Reconstruct visible text, as we do not have much control over how links @@ -69,12 +51,7 @@ const isLinkMisleading = (link, checkUrlLike = true) => { const host = targetURL.host.replace(targetURL.hostname, hostname); const origin = targetURL.origin.replace(targetURL.host, host); const text = linkText.normalize('NFKC'); - if (textMatchesTarget(text, origin, host) || textMatchesTarget(text.toLowerCase(), origin, host)) { - return false; - } - - // If the link text looks like an URL or auto-generated link, it is misleading - return !checkUrlLike || linkRegex.test(linkText); + return !(textMatchesTarget(text, origin, host) || textMatchesTarget(text.toLowerCase(), origin, host)); }; export default class StatusContent extends React.PureComponent { @@ -89,11 +66,11 @@ export default class StatusContent extends React.PureComponent { parseClick: PropTypes.func, disabled: PropTypes.bool, onUpdate: PropTypes.func, - linkRewriting: PropTypes.string, + tagLinks: PropTypes.bool, }; static defaultProps = { - linkRewriting: 'tag', + tagLinks: true, }; state = { @@ -102,7 +79,7 @@ export default class StatusContent extends React.PureComponent { _updateStatusLinks () { const node = this.contentsNode; - const { linkRewriting } = this.props; + const { tagLinks } = this.props; if (!node) { return; @@ -129,35 +106,7 @@ export default class StatusContent extends React.PureComponent { link.setAttribute('title', link.href); link.classList.add('unhandled-link'); - if (linkRewriting === 'rewrite' && isLinkMisleading(link)) { - // Rewrite misleading links entirely - - while (link.firstChild) { - link.removeChild(link.firstChild); - } - - const prefix = (link.href.match(/https?:\/\/(www\.)?/) || [''])[0]; - const text = link.href.substr(prefix.length, 30); - const suffix = link.href.substr(prefix.length + 30); - const cutoff = !!suffix; - - const prefixTag = document.createElement('span'); - prefixTag.classList.add('invisible'); - prefixTag.textContent = prefix; - link.appendChild(prefixTag); - - const textTag = document.createElement('span'); - if (cutoff) { - textTag.classList.add('ellipsis'); - } - textTag.textContent = text; - link.appendChild(textTag); - - const suffixTag = document.createElement('span'); - suffixTag.classList.add('invisible'); - suffixTag.textContent = suffix; - link.appendChild(suffixTag); - } else if (linkRewriting === 'tag' && isLinkMisleading(link, false)) { + if (tagLinks && isLinkMisleading(link)) { // Add a tag besides the link to display its origin const tag = document.createElement('span'); @@ -287,7 +236,7 @@ export default class StatusContent extends React.PureComponent { mediaIcon, parseClick, disabled, - linkRewriting, + tagLinks, } = this.props; const hidden = this.props.onExpandedToggle ? !this.props.expanded : this.state.hidden; @@ -362,7 +311,7 @@ export default class StatusContent extends React.PureComponent {
-
+
{media}
); diff --git a/app/javascript/flavours/glitch/features/local_settings/page/index.js b/app/javascript/flavours/glitch/features/local_settings/page/index.js index 3f11dc5e9f..bd92a81c2a 100644 --- a/app/javascript/flavours/glitch/features/local_settings/page/index.js +++ b/app/javascript/flavours/glitch/features/local_settings/page/index.js @@ -25,9 +25,6 @@ const messages = defineMessages({ filters_upstream: { id: 'settings.filtering_behavior.upstream', defaultMessage: 'Show "filtered" like vanilla Mastodon' }, filters_hide: { id: 'settings.filtering_behavior.hide', defaultMessage: 'Show "filtered" and add a button to display why' }, filters_cw: { id: 'settings.filtering_behavior.cw', defaultMessage: 'Still display the post, and add filtered words to content warning' }, - link_rewriting_none: { id: 'settings.link_rewriting.none', defaultMessage: 'Do not rewrite links' }, - link_rewriting_rewrite: { id: 'settings.link_rewriting.rewrite', defaultMessage: 'Rewrite links that may be misleading' }, - link_rewriting_tag: { id: 'settings.link_rewriting.tag', defaultMessage: 'Tag links with their target host unless it is already explicit' }, }); @injectIntl @@ -71,16 +68,12 @@ export default class LocalSettingsPage extends React.PureComponent { - + +

diff --git a/app/javascript/flavours/glitch/features/status/components/detailed_status.js b/app/javascript/flavours/glitch/features/status/components/detailed_status.js index 29272c0ad1..fa4ed2fd5e 100644 --- a/app/javascript/flavours/glitch/features/status/components/detailed_status.js +++ b/app/javascript/flavours/glitch/features/status/components/detailed_status.js @@ -241,7 +241,7 @@ export default class DetailedStatus extends ImmutablePureComponent { onExpandedToggle={onToggleHidden} parseClick={this.parseClick} onUpdate={this.handleChildUpdate} - linkRewriting={settings.get('link_rewriting')} + tagLinks={settings.get('tag_misleading_links')} disabled /> diff --git a/app/javascript/flavours/glitch/reducers/local_settings.js b/app/javascript/flavours/glitch/reducers/local_settings.js index b020bdfb93..7477c55846 100644 --- a/app/javascript/flavours/glitch/reducers/local_settings.js +++ b/app/javascript/flavours/glitch/reducers/local_settings.js @@ -22,7 +22,7 @@ const initialState = ImmutableMap({ hicolor_privacy_icons: false, show_content_type_choice: false, filtering_behavior: 'hide', - link_rewriting: 'tag', + tag_misleading_links: true, content_warnings : ImmutableMap({ auto_unfold : false, filter : null,