2024-07-19 00:36:09 +10:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
|
|
2024-10-16 19:33:11 +11:00
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
|
2024-07-19 00:36:09 +10:00
|
|
|
import PersonAddIcon from '@/material-icons/400-24px/person_add-fill.svg?react';
|
2024-08-16 20:00:59 +10:00
|
|
|
import { FollowersCounter } from 'mastodon/components/counters';
|
|
|
|
import { FollowButton } from 'mastodon/components/follow_button';
|
|
|
|
import { ShortNumber } from 'mastodon/components/short_number';
|
2024-10-16 19:33:11 +11:00
|
|
|
import { me } from 'mastodon/initial_state';
|
2024-07-19 00:36:09 +10:00
|
|
|
import type { NotificationGroupFollow } from 'mastodon/models/notification_group';
|
2024-08-16 20:00:59 +10:00
|
|
|
import { useAppSelector } from 'mastodon/store';
|
2024-07-19 00:36:09 +10:00
|
|
|
|
|
|
|
import type { LabelRenderer } from './notification_group_with_status';
|
|
|
|
import { NotificationGroupWithStatus } from './notification_group_with_status';
|
|
|
|
|
2024-10-16 19:33:11 +11:00
|
|
|
const labelRenderer: LabelRenderer = (displayedName, total, seeMoreHref) => {
|
2024-08-21 18:56:36 +10:00
|
|
|
if (total === 1)
|
|
|
|
return (
|
|
|
|
<FormattedMessage
|
|
|
|
id='notification.follow'
|
|
|
|
defaultMessage='{name} followed you'
|
|
|
|
values={{ name: displayedName }}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<FormattedMessage
|
|
|
|
id='notification.follow.name_and_others'
|
2024-10-16 19:33:11 +11:00
|
|
|
defaultMessage='{name} and <a>{count, plural, one {# other} other {# others}}</a> followed you'
|
2024-08-21 18:56:36 +10:00
|
|
|
values={{
|
|
|
|
name: displayedName,
|
|
|
|
count: total - 1,
|
2024-10-16 19:33:11 +11:00
|
|
|
a: (chunks) =>
|
|
|
|
seeMoreHref ? <Link to={seeMoreHref}>{chunks}</Link> : chunks,
|
2024-08-21 18:56:36 +10:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
2024-07-19 00:36:09 +10:00
|
|
|
|
2024-08-16 20:00:59 +10:00
|
|
|
const FollowerCount: React.FC<{ accountId: string }> = ({ accountId }) => {
|
|
|
|
const account = useAppSelector((s) => s.accounts.get(accountId));
|
|
|
|
|
|
|
|
if (!account) return null;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ShortNumber value={account.followers_count} renderer={FollowersCounter} />
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2024-07-19 00:36:09 +10:00
|
|
|
export const NotificationFollow: React.FC<{
|
|
|
|
notification: NotificationGroupFollow;
|
|
|
|
unread: boolean;
|
2024-08-16 20:00:59 +10:00
|
|
|
}> = ({ notification, unread }) => {
|
2024-10-16 19:33:11 +11:00
|
|
|
const username = useAppSelector(
|
|
|
|
(state) => state.accounts.getIn([me, 'username']) as string,
|
|
|
|
);
|
|
|
|
|
2024-08-16 20:00:59 +10:00
|
|
|
let actions: JSX.Element | undefined;
|
|
|
|
let additionalContent: JSX.Element | undefined;
|
|
|
|
|
|
|
|
if (notification.sampleAccountIds.length === 1) {
|
|
|
|
// only display those if the group contains 1 account, otherwise it does not makes sense
|
|
|
|
const account = notification.sampleAccountIds[0];
|
|
|
|
|
|
|
|
if (account) {
|
|
|
|
actions = <FollowButton accountId={notification.sampleAccountIds[0]} />;
|
|
|
|
additionalContent = <FollowerCount accountId={account} />;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<NotificationGroupWithStatus
|
|
|
|
type='follow'
|
|
|
|
icon={PersonAddIcon}
|
|
|
|
iconId='person-add'
|
|
|
|
accountIds={notification.sampleAccountIds}
|
|
|
|
timestamp={notification.latest_page_notification_at}
|
|
|
|
count={notification.notifications_count}
|
|
|
|
labelRenderer={labelRenderer}
|
2024-10-16 19:33:11 +11:00
|
|
|
labelSeeMoreHref={`/@${username}/followers`}
|
2024-08-16 20:00:59 +10:00
|
|
|
unread={unread}
|
|
|
|
actions={actions}
|
|
|
|
additionalContent={additionalContent}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|