diff options
author | Thibaut Girka <thib@sitedethib.com> | 2019-08-28 22:13:41 +0200 |
---|---|---|
committer | ThibG <thib@sitedethib.com> | 2019-08-29 11:59:29 +0200 |
commit | 3282bbe45413e790a5c77b2dda5b28b392a57c9f (patch) | |
tree | 1d6865418638249bec03f359e72b8d29efd503c9 /app/javascript/flavours/glitch/components/status_content.js | |
parent | 284a1562fb195d7f6d41e76511d280b2dc74ea40 (diff) |
Add option to rewrite mentions to mentioned user's username or acct
Fixes #666
Diffstat (limited to 'app/javascript/flavours/glitch/components/status_content.js')
-rw-r--r-- | app/javascript/flavours/glitch/components/status_content.js | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/app/javascript/flavours/glitch/components/status_content.js b/app/javascript/flavours/glitch/components/status_content.js index 95a4fe3fa..e45a9fc42 100644 --- a/app/javascript/flavours/glitch/components/status_content.js +++ b/app/javascript/flavours/glitch/components/status_content.js @@ -67,10 +67,12 @@ export default class StatusContent extends React.PureComponent { disabled: PropTypes.bool, onUpdate: PropTypes.func, tagLinks: PropTypes.bool, + rewriteMentions: PropTypes.string, }; static defaultProps = { tagLinks: true, + rewriteMentions: 'no', }; state = { @@ -79,7 +81,7 @@ export default class StatusContent extends React.PureComponent { _updateStatusLinks () { const node = this.contentsNode; - const { tagLinks } = this.props; + const { tagLinks, rewriteMentions } = this.props; if (!node) { return; @@ -99,6 +101,13 @@ export default class StatusContent extends React.PureComponent { if (mention) { link.addEventListener('click', this.onMentionClick.bind(this, mention), false); link.setAttribute('title', mention.get('acct')); + if (rewriteMentions !== 'no') { + while (link.firstChild) link.removeChild(link.firstChild); + link.appendChild(document.createTextNode('@')); + const acctSpan = document.createElement('span'); + acctSpan.textContent = rewriteMentions === 'acct' ? mention.get('acct') : mention.get('username'); + link.appendChild(acctSpan); + } } else if (link.textContent[0] === '#' || (link.previousSibling && link.previousSibling.textContent && link.previousSibling.textContent[link.previousSibling.textContent.length - 1] === '#')) { link.addEventListener('click', this.onHashtagClick.bind(this, link.text), false); } else { @@ -242,6 +251,7 @@ export default class StatusContent extends React.PureComponent { parseClick, disabled, tagLinks, + rewriteMentions, } = this.props; const hidden = this.props.onExpandedToggle ? !this.props.expanded : this.state.hidden; @@ -340,7 +350,7 @@ export default class StatusContent extends React.PureComponent { > <div ref={this.setContentsRef} - key={`contents-${tagLinks}`} + key={`contents-${tagLinks}-${rewriteMentions}`} dangerouslySetInnerHTML={content} lang={status.get('language')} className='status__content__text' |