import states from '../utils/states'; import store from '../utils/store'; import Avatar from './avatar'; import FollowRequestButtons from './follow-request-buttons'; import Icon from './icon'; import Link from './link'; import NameText from './name-text'; import RelativeTime from './relative-time'; import Status from './status'; const NOTIFICATION_ICONS = { mention: 'comment', status: 'notification', reblog: 'rocket', follow: 'follow', follow_request: 'follow-add', favourite: 'heart', poll: 'poll', update: 'pencil', }; /* Notification types ================== mention = Someone mentioned you in their status status = Someone you enabled notifications for has posted a status reblog = Someone boosted one of your statuses follow = Someone followed you follow_request = Someone requested to follow you favourite = Someone favourited one of your statuses poll = A poll you have voted in or created has ended update = A status you interacted with has been edited admin.sign_up = Someone signed up (optionally sent to admins) admin.report = A new report has been filed */ const contentText = { mention: 'mentioned you in their post.', status: 'published a post.', reblog: 'boosted your post.', reblog_reply: 'boosted your reply.', follow: 'followed you.', follow_request: 'requested to follow you.', favourite: 'favourited your post.', favourite_reply: 'favourited your reply.', poll: 'A poll you have voted in or created has ended.', 'poll-self': 'A poll you have created has ended.', 'poll-voted': 'A poll you have voted in has ended.', update: 'A post you interacted with has been edited.', 'favourite+reblog': 'boosted & favourited your post.', 'favourite+reblog_reply': 'boosted & favourited your reply.', }; function Notification({ notification, instance, reload }) { const { id, status, account, _accounts } = notification; let { type } = notification; // status = Attached when type of the notification is favourite, reblog, status, mention, poll, or update const actualStatusID = status?.reblog?.id || status?.id; const currentAccount = store.session.get('currentAccount'); const isSelf = currentAccount === account?.id; const isVoted = status?.poll?.voted; const isReplyToOthers = !!status?.inReplyToAccountId && status?.inReplyToAccountId !== currentAccount && status?.account?.id === currentAccount; let favsCount = 0; let reblogsCount = 0; if (type === 'favourite+reblog') { for (const account of _accounts) { if (account._types?.includes('favourite')) { favsCount++; } if (account._types?.includes('reblog')) { reblogsCount++; } } if (!reblogsCount && favsCount) type = 'favourite'; if (!favsCount && reblogsCount) type = 'reblog'; } let text; if (type === 'poll') { text = contentText[isSelf ? 'poll-self' : isVoted ? 'poll-voted' : 'poll']; } else if ( type === 'reblog' || type === 'favourite' || type === 'favourite+reblog' ) { text = contentText[isReplyToOthers ? `${type}_reply` : type] || contentText[type]; } else { text = contentText[type]; } if (type === 'mention' && !status) { // Could be deleted return null; } return (
{type === 'favourite+reblog' ? ( <> ) : ( )}
{type !== 'mention' && ( <>

{!/poll|update/i.test(type) && ( <> {_accounts?.length > 1 ? ( <> {_accounts.length} people{' '} ) : ( <> {' '} )} )} {text} {type === 'mention' && ( {' '} •{' '} )}

{type === 'follow_request' && ( { // reload(); }} /> )} )} {_accounts?.length > 1 && (

{_accounts.map((account, i) => ( <>

{' '} ))}

)} {status && ( )}
); } export default Notification;