Update notification labels for mentions (#31304)

This commit is contained in:
Renaud Chaput 2024-08-08 22:20:35 +02:00 committed by GitHub
parent 6e01a23e3b
commit 2095d0f2b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 37 additions and 24 deletions

View file

@ -2,26 +2,33 @@ import { FormattedMessage } from 'react-intl';
import AlternateEmailIcon from '@/material-icons/400-24px/alternate_email.svg?react'; import AlternateEmailIcon from '@/material-icons/400-24px/alternate_email.svg?react';
import ReplyIcon from '@/material-icons/400-24px/reply-fill.svg?react'; import ReplyIcon from '@/material-icons/400-24px/reply-fill.svg?react';
import type { StatusVisibility } from 'mastodon/api_types/statuses'; import { me } from 'mastodon/initial_state';
import type { NotificationGroupMention } from 'mastodon/models/notification_group'; import type { NotificationGroupMention } from 'mastodon/models/notification_group';
import type { Status } from 'mastodon/models/status';
import { useAppSelector } from 'mastodon/store'; import { useAppSelector } from 'mastodon/store';
import type { LabelRenderer } from './notification_group_with_status'; import type { LabelRenderer } from './notification_group_with_status';
import { NotificationWithStatus } from './notification_with_status'; import { NotificationWithStatus } from './notification_with_status';
const labelRenderer: LabelRenderer = (values) => ( const mentionLabelRenderer: LabelRenderer = () => (
<FormattedMessage id='notification.label.mention' defaultMessage='Mention' />
);
const privateMentionLabelRenderer: LabelRenderer = () => (
<FormattedMessage <FormattedMessage
id='notification.mention' id='notification.label.private_mention'
defaultMessage='{name} mentioned you' defaultMessage='Private mention'
values={values}
/> />
); );
const privateMentionLabelRenderer: LabelRenderer = (values) => ( const replyLabelRenderer: LabelRenderer = () => (
<FormattedMessage id='notification.label.reply' defaultMessage='Reply' />
);
const privateReplyLabelRenderer: LabelRenderer = () => (
<FormattedMessage <FormattedMessage
id='notification.private_mention' id='notification.label.private_reply'
defaultMessage='{name} privately mentioned you' defaultMessage='Private reply'
values={values}
/> />
); );
@ -29,27 +36,30 @@ export const NotificationMention: React.FC<{
notification: NotificationGroupMention; notification: NotificationGroupMention;
unread: boolean; unread: boolean;
}> = ({ notification, unread }) => { }> = ({ notification, unread }) => {
const statusVisibility = useAppSelector( const [isDirect, isReply] = useAppSelector((state) => {
(state) => const status = state.statuses.get(notification.statusId) as Status;
state.statuses.getIn([
notification.statusId, return [
'visibility', status.get('visibility') === 'direct',
]) as StatusVisibility, status.get('in_reply_to_account_id') === me,
); ] as const;
});
let labelRenderer = mentionLabelRenderer;
if (isReply && isDirect) labelRenderer = privateReplyLabelRenderer;
else if (isReply) labelRenderer = replyLabelRenderer;
else if (isDirect) labelRenderer = privateMentionLabelRenderer;
return ( return (
<NotificationWithStatus <NotificationWithStatus
type='mention' type='mention'
icon={statusVisibility === 'direct' ? AlternateEmailIcon : ReplyIcon} icon={isReply ? ReplyIcon : AlternateEmailIcon}
iconId='reply' iconId='reply'
accountIds={notification.sampleAccountIds} accountIds={notification.sampleAccountIds}
count={notification.notifications_count} count={notification.notifications_count}
statusId={notification.statusId} statusId={notification.statusId}
labelRenderer={ labelRenderer={labelRenderer}
statusVisibility === 'direct'
? privateMentionLabelRenderer
: labelRenderer
}
unread={unread} unread={unread}
/> />
); );

View file

@ -482,7 +482,11 @@
"notification.favourite": "{name} favorited your post", "notification.favourite": "{name} favorited your post",
"notification.follow": "{name} followed you", "notification.follow": "{name} followed you",
"notification.follow_request": "{name} has requested to follow you", "notification.follow_request": "{name} has requested to follow you",
"notification.mention": "{name} mentioned you", "notification.label.mention": "Mention",
"notification.label.private_mention": "Private mention",
"notification.label.private_reply": "Private reply",
"notification.label.reply": "Reply",
"notification.mention": "Mention",
"notification.moderation-warning.learn_more": "Learn more", "notification.moderation-warning.learn_more": "Learn more",
"notification.moderation_warning": "You have received a moderation warning", "notification.moderation_warning": "You have received a moderation warning",
"notification.moderation_warning.action_delete_statuses": "Some of your posts have been removed.", "notification.moderation_warning.action_delete_statuses": "Some of your posts have been removed.",
@ -494,7 +498,6 @@
"notification.moderation_warning.action_suspend": "Your account has been suspended.", "notification.moderation_warning.action_suspend": "Your account has been suspended.",
"notification.own_poll": "Your poll has ended", "notification.own_poll": "Your poll has ended",
"notification.poll": "A poll you voted in has ended", "notification.poll": "A poll you voted in has ended",
"notification.private_mention": "{name} privately mentioned you",
"notification.reblog": "{name} boosted your post", "notification.reblog": "{name} boosted your post",
"notification.relationships_severance_event": "Lost connections with {name}", "notification.relationships_severance_event": "Lost connections with {name}",
"notification.relationships_severance_event.account_suspension": "An admin from {from} has suspended {target}, which means you can no longer receive updates from them or interact with them.", "notification.relationships_severance_event.account_suspension": "An admin from {from} has suspended {target}, which means you can no longer receive updates from them or interact with them.",