[Glitch] Update notification labels for mentions

Port 2095d0f2b08c52a39380bb8b303851e475c6b3a7 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Renaud Chaput 2024-08-08 22:20:35 +02:00 committed by Claire
parent e7be55fd73
commit 5a9f526a17

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 'flavours/glitch/api_types/statuses'; import { me } from 'flavours/glitch/initial_state';
import type { NotificationGroupMention } from 'flavours/glitch/models/notification_group'; import type { NotificationGroupMention } from 'flavours/glitch/models/notification_group';
import type { Status } from 'flavours/glitch/models/status';
import { useAppSelector } from 'flavours/glitch/store'; import { useAppSelector } from 'flavours/glitch/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}
/> />
); );