2023-02-12 14:29:03 +03:00
|
|
|
import './account-block.css';
|
|
|
|
|
2024-08-13 10:26:23 +03:00
|
|
|
import { Plural, t, Trans } from '@lingui/macro';
|
|
|
|
|
2023-09-03 14:48:36 +03:00
|
|
|
// import { useNavigate } from 'react-router-dom';
|
2023-07-02 13:02:30 +03:00
|
|
|
import enhanceContent from '../utils/enhance-content';
|
2023-03-07 17:36:12 +03:00
|
|
|
import niceDateTime from '../utils/nice-date-time';
|
2023-12-20 08:55:56 +03:00
|
|
|
import shortenNumber from '../utils/shorten-number';
|
2023-02-12 14:29:03 +03:00
|
|
|
import states from '../utils/states';
|
|
|
|
|
|
|
|
import Avatar from './avatar';
|
2023-06-14 12:37:41 +03:00
|
|
|
import EmojiText from './emoji-text';
|
2023-07-02 13:02:30 +03:00
|
|
|
import Icon from './icon';
|
2023-02-12 14:29:03 +03:00
|
|
|
|
|
|
|
function AccountBlock({
|
|
|
|
skeleton,
|
|
|
|
account,
|
|
|
|
avatarSize = 'xl',
|
2023-11-12 06:01:44 +03:00
|
|
|
useAvatarStatic = false,
|
2023-02-12 14:29:03 +03:00
|
|
|
instance,
|
|
|
|
external,
|
2023-03-11 09:05:56 +03:00
|
|
|
internal,
|
2023-02-12 14:29:03 +03:00
|
|
|
onClick,
|
2023-03-07 17:36:12 +03:00
|
|
|
showActivity = false,
|
2023-07-02 13:02:30 +03:00
|
|
|
showStats = false,
|
2023-09-03 14:48:36 +03:00
|
|
|
accountInstance,
|
|
|
|
hideDisplayName = false,
|
2023-12-20 08:55:56 +03:00
|
|
|
relationship = {},
|
|
|
|
excludeRelationshipAttrs = [],
|
2023-02-12 14:29:03 +03:00
|
|
|
}) {
|
|
|
|
if (skeleton) {
|
|
|
|
return (
|
|
|
|
<div class="account-block skeleton">
|
|
|
|
<Avatar size={avatarSize} />
|
|
|
|
<span>
|
|
|
|
<b>████████</b>
|
|
|
|
<br />
|
2024-03-18 06:48:15 +03:00
|
|
|
<span class="account-block-acct">██████</span>
|
2023-02-12 14:29:03 +03:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-12-22 18:02:44 +03:00
|
|
|
if (!account) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-09-03 14:48:36 +03:00
|
|
|
// const navigate = useNavigate();
|
2023-03-11 09:05:56 +03:00
|
|
|
|
2023-03-07 17:36:12 +03:00
|
|
|
const {
|
2023-03-11 09:05:56 +03:00
|
|
|
id,
|
2023-03-07 17:36:12 +03:00
|
|
|
acct,
|
|
|
|
avatar,
|
|
|
|
avatarStatic,
|
|
|
|
displayName,
|
|
|
|
username,
|
|
|
|
emojis,
|
|
|
|
url,
|
|
|
|
statusesCount,
|
|
|
|
lastStatusAt,
|
2023-04-10 19:26:43 +03:00
|
|
|
bot,
|
2023-07-02 13:02:30 +03:00
|
|
|
fields,
|
|
|
|
note,
|
2023-08-07 16:26:56 +03:00
|
|
|
group,
|
2023-12-20 08:55:56 +03:00
|
|
|
followersCount,
|
2024-01-30 17:46:18 +03:00
|
|
|
createdAt,
|
2024-03-07 04:05:40 +03:00
|
|
|
locked,
|
2023-03-07 17:36:12 +03:00
|
|
|
} = account;
|
2023-09-03 14:48:36 +03:00
|
|
|
let [_, acct1, acct2] = acct.match(/([^@]+)(@.+)/i) || [, acct];
|
|
|
|
if (accountInstance) {
|
|
|
|
acct2 = `@${accountInstance}`;
|
|
|
|
}
|
2023-02-12 14:29:03 +03:00
|
|
|
|
2023-07-02 13:02:30 +03:00
|
|
|
const verifiedField = fields?.find((f) => !!f.verifiedAt && !!f.value);
|
|
|
|
|
2023-12-20 08:55:56 +03:00
|
|
|
const excludedRelationship = {};
|
|
|
|
for (const r in relationship) {
|
|
|
|
if (!excludeRelationshipAttrs.includes(r)) {
|
|
|
|
excludedRelationship[r] = relationship[r];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const hasRelationship =
|
|
|
|
excludedRelationship.following ||
|
|
|
|
excludedRelationship.followedBy ||
|
|
|
|
excludedRelationship.requested;
|
|
|
|
|
2023-02-12 14:29:03 +03:00
|
|
|
return (
|
|
|
|
<a
|
|
|
|
class="account-block"
|
|
|
|
href={url}
|
|
|
|
target={external ? '_blank' : null}
|
2024-03-18 06:48:15 +03:00
|
|
|
title={acct2 ? acct : `@${acct}`}
|
2023-02-12 14:29:03 +03:00
|
|
|
onClick={(e) => {
|
|
|
|
if (external) return;
|
|
|
|
e.preventDefault();
|
|
|
|
if (onClick) return onClick(e);
|
2023-03-11 09:05:56 +03:00
|
|
|
if (internal) {
|
2023-09-03 14:48:36 +03:00
|
|
|
// navigate(`/${instance}/a/${id}`);
|
|
|
|
location.hash = `/${instance}/a/${id}`;
|
2023-03-11 09:05:56 +03:00
|
|
|
} else {
|
|
|
|
states.showAccount = {
|
|
|
|
account,
|
|
|
|
instance,
|
|
|
|
};
|
|
|
|
}
|
2023-02-12 14:29:03 +03:00
|
|
|
}}
|
|
|
|
>
|
2023-11-12 06:01:44 +03:00
|
|
|
<Avatar
|
|
|
|
url={useAvatarStatic ? avatarStatic : avatar || avatarStatic}
|
|
|
|
size={avatarSize}
|
|
|
|
squircle={bot}
|
|
|
|
/>
|
2023-11-02 12:38:38 +03:00
|
|
|
<span class="account-block-content">
|
2023-09-03 14:48:36 +03:00
|
|
|
{!hideDisplayName && (
|
|
|
|
<>
|
|
|
|
{displayName ? (
|
|
|
|
<b>
|
|
|
|
<EmojiText text={displayName} emojis={emojis} />
|
|
|
|
</b>
|
|
|
|
) : (
|
|
|
|
<b>{username}</b>
|
|
|
|
)}
|
|
|
|
</>
|
2023-12-20 08:55:56 +03:00
|
|
|
)}{' '}
|
2024-08-04 08:32:30 +03:00
|
|
|
<span class="account-block-acct bidi-isolate">
|
2024-03-18 06:48:15 +03:00
|
|
|
{acct2 ? '' : '@'}
|
|
|
|
{acct1}
|
2023-03-11 09:05:56 +03:00
|
|
|
<wbr />
|
|
|
|
{acct2}
|
2024-03-07 04:05:40 +03:00
|
|
|
{locked && (
|
|
|
|
<>
|
|
|
|
{' '}
|
2024-08-13 10:26:23 +03:00
|
|
|
<Icon icon="lock" size="s" alt={t`Locked`} />
|
2024-03-07 04:05:40 +03:00
|
|
|
</>
|
|
|
|
)}
|
2023-03-11 09:05:56 +03:00
|
|
|
</span>
|
2023-03-07 17:36:12 +03:00
|
|
|
{showActivity && (
|
2024-05-25 06:06:58 +03:00
|
|
|
<div class="account-block-stats">
|
2024-08-13 10:26:23 +03:00
|
|
|
<Trans>Posts: {shortenNumber(statusesCount)}</Trans>
|
2024-05-25 06:06:58 +03:00
|
|
|
{!!lastStatusAt && (
|
|
|
|
<>
|
|
|
|
{' '}
|
2024-08-13 10:26:23 +03:00
|
|
|
·{' '}
|
|
|
|
<Trans>
|
|
|
|
Last posted:{' '}
|
|
|
|
{niceDateTime(lastStatusAt, {
|
|
|
|
hideTime: true,
|
|
|
|
})}
|
|
|
|
</Trans>
|
2024-05-25 06:06:58 +03:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
2023-03-07 17:36:12 +03:00
|
|
|
)}
|
2023-07-02 13:02:30 +03:00
|
|
|
{showStats && (
|
|
|
|
<div class="account-block-stats">
|
|
|
|
{bot && (
|
|
|
|
<>
|
2023-12-20 08:55:56 +03:00
|
|
|
<span class="tag collapsed">
|
2024-08-13 10:26:23 +03:00
|
|
|
<Icon icon="bot" /> <Trans>Automated</Trans>
|
2023-07-02 13:02:30 +03:00
|
|
|
</span>
|
|
|
|
</>
|
|
|
|
)}
|
2023-08-07 16:26:56 +03:00
|
|
|
{!!group && (
|
|
|
|
<>
|
2023-12-20 08:55:56 +03:00
|
|
|
<span class="tag collapsed">
|
2024-08-13 10:26:23 +03:00
|
|
|
<Icon icon="group" /> <Trans>Group</Trans>
|
2023-08-07 16:26:56 +03:00
|
|
|
</span>
|
|
|
|
</>
|
|
|
|
)}
|
2023-12-20 08:55:56 +03:00
|
|
|
{hasRelationship && (
|
|
|
|
<div key={relationship.id} class="shazam-container-horizontal">
|
|
|
|
<div class="shazam-container-inner">
|
|
|
|
{excludedRelationship.following &&
|
|
|
|
excludedRelationship.followedBy ? (
|
2024-08-13 10:26:23 +03:00
|
|
|
<span class="tag minimal">
|
|
|
|
<Trans>Mutual</Trans>
|
|
|
|
</span>
|
2023-12-20 08:55:56 +03:00
|
|
|
) : excludedRelationship.requested ? (
|
2024-08-13 10:26:23 +03:00
|
|
|
<span class="tag minimal">
|
|
|
|
<Trans>Requested</Trans>
|
|
|
|
</span>
|
2023-12-20 08:55:56 +03:00
|
|
|
) : excludedRelationship.following ? (
|
2024-08-13 10:26:23 +03:00
|
|
|
<span class="tag minimal">
|
|
|
|
<Trans>Following</Trans>
|
|
|
|
</span>
|
2023-12-20 08:55:56 +03:00
|
|
|
) : excludedRelationship.followedBy ? (
|
2024-08-13 10:26:23 +03:00
|
|
|
<span class="tag minimal">
|
|
|
|
<Trans>Follows you</Trans>
|
|
|
|
</span>
|
2023-12-20 08:55:56 +03:00
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{!!followersCount && (
|
|
|
|
<span class="ib">
|
2024-08-13 10:26:23 +03:00
|
|
|
<Plural
|
|
|
|
value={followersCount}
|
|
|
|
one="# follower"
|
|
|
|
other="# followers"
|
|
|
|
/>
|
2023-12-20 08:55:56 +03:00
|
|
|
</span>
|
|
|
|
)}
|
2023-07-02 13:02:30 +03:00
|
|
|
{!!verifiedField && (
|
2023-12-20 08:55:56 +03:00
|
|
|
<span class="verified-field">
|
2024-08-13 10:26:23 +03:00
|
|
|
<Icon icon="check-circle" size="s" alt={t`Verified`} />{' '}
|
2023-07-02 13:02:30 +03:00
|
|
|
<span
|
|
|
|
dangerouslySetInnerHTML={{
|
|
|
|
__html: enhanceContent(verifiedField.value, { emojis }),
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
)}
|
2024-01-30 17:46:18 +03:00
|
|
|
{!bot &&
|
|
|
|
!group &&
|
|
|
|
!hasRelationship &&
|
|
|
|
!followersCount &&
|
|
|
|
!verifiedField &&
|
|
|
|
!!createdAt && (
|
|
|
|
<span class="created-at">
|
2024-08-13 10:26:23 +03:00
|
|
|
<Trans>
|
|
|
|
Joined{' '}
|
|
|
|
<time datetime={createdAt}>
|
|
|
|
{niceDateTime(createdAt, {
|
|
|
|
hideTime: true,
|
|
|
|
})}
|
|
|
|
</time>
|
|
|
|
</Trans>
|
2024-01-30 17:46:18 +03:00
|
|
|
</span>
|
|
|
|
)}
|
2023-07-02 13:02:30 +03:00
|
|
|
</div>
|
|
|
|
)}
|
2023-02-12 14:29:03 +03:00
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default AccountBlock;
|