2024-08-03 00:59:37 +10:00
|
|
|
import { useCallback } from 'react';
|
|
|
|
|
2024-08-10 00:21:55 +10:00
|
|
|
import { useIntl, defineMessages, FormattedMessage } from 'react-intl';
|
2024-08-03 00:59:37 +10:00
|
|
|
|
2024-08-10 00:21:55 +10:00
|
|
|
import { openModal } from 'mastodon/actions/modal';
|
2024-08-03 00:59:37 +10:00
|
|
|
import { updateNotificationsPolicy } from 'mastodon/actions/notification_policies';
|
2024-08-10 00:21:55 +10:00
|
|
|
import type { AppDispatch } from 'mastodon/store';
|
2024-08-03 00:59:37 +10:00
|
|
|
import { useAppSelector, useAppDispatch } from 'mastodon/store';
|
|
|
|
|
2024-08-10 00:21:55 +10:00
|
|
|
import { SelectWithLabel } from './select_with_label';
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
accept: { id: 'notifications.policy.accept', defaultMessage: 'Accept' },
|
|
|
|
accept_hint: {
|
|
|
|
id: 'notifications.policy.accept_hint',
|
|
|
|
defaultMessage: 'Show in notifications',
|
|
|
|
},
|
|
|
|
filter: { id: 'notifications.policy.filter', defaultMessage: 'Filter' },
|
|
|
|
filter_hint: {
|
|
|
|
id: 'notifications.policy.filter_hint',
|
|
|
|
defaultMessage: 'Send to filtered notifications inbox',
|
|
|
|
},
|
|
|
|
drop: { id: 'notifications.policy.drop', defaultMessage: 'Ignore' },
|
|
|
|
drop_hint: {
|
|
|
|
id: 'notifications.policy.drop_hint',
|
|
|
|
defaultMessage: 'Send to the void, never to be seen again',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// TODO: change the following when we change the API
|
|
|
|
const changeFilter = (
|
|
|
|
dispatch: AppDispatch,
|
|
|
|
filterType: string,
|
|
|
|
value: string,
|
|
|
|
) => {
|
|
|
|
if (value === 'drop') {
|
|
|
|
dispatch(
|
|
|
|
openModal({
|
|
|
|
modalType: 'IGNORE_NOTIFICATIONS',
|
|
|
|
modalProps: { filterType },
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
void dispatch(updateNotificationsPolicy({ [filterType]: value }));
|
|
|
|
}
|
|
|
|
};
|
2024-08-08 09:09:30 +10:00
|
|
|
|
2024-08-03 00:59:37 +10:00
|
|
|
export const PolicyControls: React.FC = () => {
|
2024-08-10 00:21:55 +10:00
|
|
|
const intl = useIntl();
|
2024-08-03 00:59:37 +10:00
|
|
|
const dispatch = useAppDispatch();
|
|
|
|
|
|
|
|
const notificationPolicy = useAppSelector(
|
|
|
|
(state) => state.notificationPolicy,
|
|
|
|
);
|
|
|
|
|
|
|
|
const handleFilterNotFollowing = useCallback(
|
2024-08-10 00:21:55 +10:00
|
|
|
(value: string) => {
|
|
|
|
changeFilter(dispatch, 'for_not_following', value);
|
2024-08-03 00:59:37 +10:00
|
|
|
},
|
|
|
|
[dispatch],
|
|
|
|
);
|
|
|
|
|
|
|
|
const handleFilterNotFollowers = useCallback(
|
2024-08-10 00:21:55 +10:00
|
|
|
(value: string) => {
|
|
|
|
changeFilter(dispatch, 'for_not_followers', value);
|
2024-08-03 00:59:37 +10:00
|
|
|
},
|
|
|
|
[dispatch],
|
|
|
|
);
|
|
|
|
|
|
|
|
const handleFilterNewAccounts = useCallback(
|
2024-08-10 00:21:55 +10:00
|
|
|
(value: string) => {
|
|
|
|
changeFilter(dispatch, 'for_new_accounts', value);
|
2024-08-03 00:59:37 +10:00
|
|
|
},
|
|
|
|
[dispatch],
|
|
|
|
);
|
|
|
|
|
|
|
|
const handleFilterPrivateMentions = useCallback(
|
2024-08-10 00:21:55 +10:00
|
|
|
(value: string) => {
|
|
|
|
changeFilter(dispatch, 'for_private_mentions', value);
|
|
|
|
},
|
|
|
|
[dispatch],
|
|
|
|
);
|
|
|
|
|
|
|
|
const handleFilterLimitedAccounts = useCallback(
|
|
|
|
(value: string) => {
|
|
|
|
changeFilter(dispatch, 'for_limited_accounts', value);
|
2024-08-03 00:59:37 +10:00
|
|
|
},
|
|
|
|
[dispatch],
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!notificationPolicy) return null;
|
|
|
|
|
2024-08-10 00:21:55 +10:00
|
|
|
const options = [
|
|
|
|
{
|
|
|
|
value: 'accept',
|
|
|
|
text: intl.formatMessage(messages.accept),
|
|
|
|
meta: intl.formatMessage(messages.accept_hint),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'filter',
|
|
|
|
text: intl.formatMessage(messages.filter),
|
|
|
|
meta: intl.formatMessage(messages.filter_hint),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'drop',
|
|
|
|
text: intl.formatMessage(messages.drop),
|
|
|
|
meta: intl.formatMessage(messages.drop_hint),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2024-08-03 00:59:37 +10:00
|
|
|
return (
|
|
|
|
<section>
|
|
|
|
<h3>
|
|
|
|
<FormattedMessage
|
|
|
|
id='notifications.policy.title'
|
2024-08-10 00:21:55 +10:00
|
|
|
defaultMessage='Manage notifications from…'
|
2024-08-03 00:59:37 +10:00
|
|
|
/>
|
|
|
|
</h3>
|
|
|
|
|
|
|
|
<div className='column-settings__row'>
|
2024-08-10 00:21:55 +10:00
|
|
|
<SelectWithLabel
|
|
|
|
value={notificationPolicy.for_not_following}
|
2024-08-03 00:59:37 +10:00
|
|
|
onChange={handleFilterNotFollowing}
|
2024-08-10 00:21:55 +10:00
|
|
|
options={options}
|
2024-08-03 00:59:37 +10:00
|
|
|
>
|
|
|
|
<strong>
|
|
|
|
<FormattedMessage
|
|
|
|
id='notifications.policy.filter_not_following_title'
|
|
|
|
defaultMessage="People you don't follow"
|
|
|
|
/>
|
|
|
|
</strong>
|
|
|
|
<span className='hint'>
|
|
|
|
<FormattedMessage
|
|
|
|
id='notifications.policy.filter_not_following_hint'
|
|
|
|
defaultMessage='Until you manually approve them'
|
|
|
|
/>
|
|
|
|
</span>
|
2024-08-10 00:21:55 +10:00
|
|
|
</SelectWithLabel>
|
2024-08-03 00:59:37 +10:00
|
|
|
|
2024-08-10 00:21:55 +10:00
|
|
|
<SelectWithLabel
|
|
|
|
value={notificationPolicy.for_not_followers}
|
2024-08-03 00:59:37 +10:00
|
|
|
onChange={handleFilterNotFollowers}
|
2024-08-10 00:21:55 +10:00
|
|
|
options={options}
|
2024-08-03 00:59:37 +10:00
|
|
|
>
|
|
|
|
<strong>
|
|
|
|
<FormattedMessage
|
|
|
|
id='notifications.policy.filter_not_followers_title'
|
|
|
|
defaultMessage='People not following you'
|
|
|
|
/>
|
|
|
|
</strong>
|
|
|
|
<span className='hint'>
|
|
|
|
<FormattedMessage
|
|
|
|
id='notifications.policy.filter_not_followers_hint'
|
|
|
|
defaultMessage='Including people who have been following you fewer than {days, plural, one {one day} other {# days}}'
|
|
|
|
values={{ days: 3 }}
|
|
|
|
/>
|
|
|
|
</span>
|
2024-08-10 00:21:55 +10:00
|
|
|
</SelectWithLabel>
|
2024-08-03 00:59:37 +10:00
|
|
|
|
2024-08-10 00:21:55 +10:00
|
|
|
<SelectWithLabel
|
|
|
|
value={notificationPolicy.for_new_accounts}
|
2024-08-03 00:59:37 +10:00
|
|
|
onChange={handleFilterNewAccounts}
|
2024-08-10 00:21:55 +10:00
|
|
|
options={options}
|
2024-08-03 00:59:37 +10:00
|
|
|
>
|
|
|
|
<strong>
|
|
|
|
<FormattedMessage
|
|
|
|
id='notifications.policy.filter_new_accounts_title'
|
|
|
|
defaultMessage='New accounts'
|
|
|
|
/>
|
|
|
|
</strong>
|
|
|
|
<span className='hint'>
|
|
|
|
<FormattedMessage
|
|
|
|
id='notifications.policy.filter_new_accounts.hint'
|
|
|
|
defaultMessage='Created within the past {days, plural, one {one day} other {# days}}'
|
|
|
|
values={{ days: 30 }}
|
|
|
|
/>
|
|
|
|
</span>
|
2024-08-10 00:21:55 +10:00
|
|
|
</SelectWithLabel>
|
2024-08-03 00:59:37 +10:00
|
|
|
|
2024-08-10 00:21:55 +10:00
|
|
|
<SelectWithLabel
|
|
|
|
value={notificationPolicy.for_private_mentions}
|
2024-08-03 00:59:37 +10:00
|
|
|
onChange={handleFilterPrivateMentions}
|
2024-08-10 00:21:55 +10:00
|
|
|
options={options}
|
2024-08-03 00:59:37 +10:00
|
|
|
>
|
|
|
|
<strong>
|
|
|
|
<FormattedMessage
|
|
|
|
id='notifications.policy.filter_private_mentions_title'
|
|
|
|
defaultMessage='Unsolicited private mentions'
|
|
|
|
/>
|
|
|
|
</strong>
|
|
|
|
<span className='hint'>
|
|
|
|
<FormattedMessage
|
|
|
|
id='notifications.policy.filter_private_mentions_hint'
|
|
|
|
defaultMessage="Filtered unless it's in reply to your own mention or if you follow the sender"
|
|
|
|
/>
|
|
|
|
</span>
|
2024-08-10 00:21:55 +10:00
|
|
|
</SelectWithLabel>
|
2024-08-08 09:09:30 +10:00
|
|
|
|
2024-08-10 00:21:55 +10:00
|
|
|
<SelectWithLabel
|
|
|
|
value={notificationPolicy.for_limited_accounts}
|
|
|
|
onChange={handleFilterLimitedAccounts}
|
|
|
|
options={options}
|
|
|
|
>
|
2024-08-08 09:09:30 +10:00
|
|
|
<strong>
|
|
|
|
<FormattedMessage
|
|
|
|
id='notifications.policy.filter_limited_accounts_title'
|
|
|
|
defaultMessage='Moderated accounts'
|
|
|
|
/>
|
|
|
|
</strong>
|
|
|
|
<span className='hint'>
|
|
|
|
<FormattedMessage
|
|
|
|
id='notifications.policy.filter_limited_accounts_hint'
|
|
|
|
defaultMessage='Limited by server moderators'
|
|
|
|
/>
|
|
|
|
</span>
|
2024-08-10 00:21:55 +10:00
|
|
|
</SelectWithLabel>
|
2024-08-03 00:59:37 +10:00
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
);
|
|
|
|
};
|