Add option to rewrite mentions to mentioned user's username or acct

Fixes #666
rebase/4.0.0rc2
Thibaut Girka 2019-08-28 22:13:41 +02:00 committed by ThibG
parent 284a1562fb
commit 3282bbe454
5 changed files with 31 additions and 2 deletions

View File

@ -702,6 +702,7 @@ class Status extends ImmutablePureComponent {
parseClick={parseClick}
disabled={!router}
tagLinks={settings.get('tag_misleading_links')}
rewriteMentions={settings.get('rewrite_mentions')}
/>
{!isCollapsed || !(muted || !settings.getIn(['collapsed', 'show_action_bar'])) ? (
<StatusActionBar

View File

@ -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'

View File

@ -25,6 +25,9 @@ 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' },
rewrite_mentions_no: { id: 'settings.rewrite_mentions_no', defaultMessage: 'Do not rewrite mentions' },
rewrite_mentions_acct: { id: 'settings.rewrite_mentions_acct', defaultMessage: 'Rewrite with username and domain (when the account is remote)' },
rewrite_mentions_username: { id: 'settings.rewrite_mentions_username', defaultMessage: 'Rewrite with username' },
});
@injectIntl
@ -75,6 +78,19 @@ export default class LocalSettingsPage extends React.PureComponent {
<FormattedMessage id='settings.tag_misleading_links' defaultMessage='Tag misleading links' />
<span className='hint'><FormattedMessage id='settings.tag_misleading_links.hint' defaultMessage="Add a visual indication with the link target host to every link not mentioning it explicitly" /></span>
</LocalSettingsPageItem>
<LocalSettingsPageItem
settings={settings}
item={['rewrite_mentions']}
id='mastodon-settings--rewrite_mentions'
options={[
{ value: 'no', message: intl.formatMessage(messages.rewrite_mentions_no) },
{ value: 'acct', message: intl.formatMessage(messages.rewrite_mentions_acct) },
{ value: 'username', message: intl.formatMessage(messages.rewrite_mentions_username) },
]}
onChange={onChange}
>
<FormattedMessage id='settings.rewrite_mentions' defaultMessage='Rewrite mentions in displayed statuses' />
</LocalSettingsPageItem>
<section>
<h2><FormattedMessage id='settings.notifications_opts' defaultMessage='Notifications options' /></h2>
<LocalSettingsPageItem

View File

@ -242,6 +242,7 @@ export default class DetailedStatus extends ImmutablePureComponent {
parseClick={this.parseClick}
onUpdate={this.handleChildUpdate}
tagLinks={settings.get('tag_misleading_links')}
rewriteMentions={settings.get('rewrite_mentions')}
disabled
/>

View File

@ -23,6 +23,7 @@ const initialState = ImmutableMap({
show_content_type_choice: false,
filtering_behavior: 'hide',
tag_misleading_links: true,
rewrite_mentions: 'no',
content_warnings : ImmutableMap({
auto_unfold : false,
filter : null,