Account: normalize favicon and domain, clean up account.tsx
This commit is contained in:
parent
e5ca5464b7
commit
f577f6fcbe
|
@ -5,7 +5,7 @@ import HoverRefWrapper from 'soapbox/components/hover_ref_wrapper';
|
||||||
import VerificationBadge from 'soapbox/components/verification_badge';
|
import VerificationBadge from 'soapbox/components/verification_badge';
|
||||||
import ActionButton from 'soapbox/features/ui/components/action_button';
|
import ActionButton from 'soapbox/features/ui/components/action_button';
|
||||||
import { useAppSelector, useOnScreen } from 'soapbox/hooks';
|
import { useAppSelector, useOnScreen } from 'soapbox/hooks';
|
||||||
import { getAcct, getDomain } from 'soapbox/utils/accounts';
|
import { getAcct } from 'soapbox/utils/accounts';
|
||||||
import { displayFqn } from 'soapbox/utils/state';
|
import { displayFqn } from 'soapbox/utils/state';
|
||||||
|
|
||||||
import RelativeTimestamp from './relative_timestamp';
|
import RelativeTimestamp from './relative_timestamp';
|
||||||
|
@ -91,7 +91,7 @@ const Account = ({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (account.get('id') !== me && account.get('relationship', null) !== null) {
|
if (account.id !== me) {
|
||||||
return <ActionButton account={account} />;
|
return <ActionButton account={account} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,8 +118,8 @@ const Account = ({
|
||||||
if (hidden) {
|
if (hidden) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{account.get('display_name')}
|
{account.display_name}
|
||||||
{account.get('username')}
|
{account.username}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -128,34 +128,31 @@ const Account = ({
|
||||||
|
|
||||||
const LinkEl: any = showProfileHoverCard ? Link : 'div';
|
const LinkEl: any = showProfileHoverCard ? Link : 'div';
|
||||||
|
|
||||||
const favicon = account.pleroma.get('favicon');
|
|
||||||
const domain = getDomain(account);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div data-testid='account' className='flex-shrink-0 group block w-full' ref={overflowRef}>
|
<div data-testid='account' className='flex-shrink-0 group block w-full' ref={overflowRef}>
|
||||||
<HStack alignItems={actionAlignment} justifyContent='between'>
|
<HStack alignItems={actionAlignment} justifyContent='between'>
|
||||||
<HStack alignItems='center' space={3} grow>
|
<HStack alignItems='center' space={3} grow>
|
||||||
<ProfilePopper
|
<ProfilePopper
|
||||||
condition={showProfileHoverCard}
|
condition={showProfileHoverCard}
|
||||||
wrapper={(children) => <HoverRefWrapper accountId={account.get('id')} inline>{children}</HoverRefWrapper>}
|
wrapper={(children) => <HoverRefWrapper accountId={account.id} inline>{children}</HoverRefWrapper>}
|
||||||
>
|
>
|
||||||
<LinkEl
|
<LinkEl
|
||||||
to={`/@${account.get('acct')}`}
|
to={`/@${account.acct}`}
|
||||||
title={account.get('acct')}
|
title={account.acct}
|
||||||
onClick={(event: React.MouseEvent) => event.stopPropagation()}
|
onClick={(event: React.MouseEvent) => event.stopPropagation()}
|
||||||
>
|
>
|
||||||
<Avatar src={account.get('avatar')} size={avatarSize} />
|
<Avatar src={account.avatar} size={avatarSize} />
|
||||||
</LinkEl>
|
</LinkEl>
|
||||||
</ProfilePopper>
|
</ProfilePopper>
|
||||||
|
|
||||||
<div className='flex-grow'>
|
<div className='flex-grow'>
|
||||||
<ProfilePopper
|
<ProfilePopper
|
||||||
condition={showProfileHoverCard}
|
condition={showProfileHoverCard}
|
||||||
wrapper={(children) => <HoverRefWrapper accountId={account.get('id')} inline>{children}</HoverRefWrapper>}
|
wrapper={(children) => <HoverRefWrapper accountId={account.id} inline>{children}</HoverRefWrapper>}
|
||||||
>
|
>
|
||||||
<LinkEl
|
<LinkEl
|
||||||
to={`/@${account.get('acct')}`}
|
to={`/@${account.acct}`}
|
||||||
title={account.get('acct')}
|
title={account.acct}
|
||||||
onClick={(event: React.MouseEvent) => event.stopPropagation()}
|
onClick={(event: React.MouseEvent) => event.stopPropagation()}
|
||||||
>
|
>
|
||||||
<div className='flex items-center space-x-1 flex-grow' style={style}>
|
<div className='flex items-center space-x-1 flex-grow' style={style}>
|
||||||
|
@ -163,10 +160,10 @@ const Account = ({
|
||||||
size='sm'
|
size='sm'
|
||||||
weight='semibold'
|
weight='semibold'
|
||||||
truncate
|
truncate
|
||||||
dangerouslySetInnerHTML={{ __html: account.get('display_name_html') }}
|
dangerouslySetInnerHTML={{ __html: account.display_name_html }}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{account.get('verified') && <VerificationBadge />}
|
{account.verified && <VerificationBadge />}
|
||||||
</div>
|
</div>
|
||||||
</LinkEl>
|
</LinkEl>
|
||||||
</ProfilePopper>
|
</ProfilePopper>
|
||||||
|
@ -174,9 +171,9 @@ const Account = ({
|
||||||
<HStack alignItems='center' space={1} style={style}>
|
<HStack alignItems='center' space={1} style={style}>
|
||||||
<Text theme='muted' size='sm' truncate>@{username}</Text>
|
<Text theme='muted' size='sm' truncate>@{username}</Text>
|
||||||
|
|
||||||
{favicon && (
|
{account.favicon && (
|
||||||
<Link to={`/timeline/${domain}`} className='w-4 h-4 flex-none'>
|
<Link to={`/timeline/${account.domain}`} className='w-4 h-4 flex-none' onClick={e => e.stopPropagation()}>
|
||||||
<img src={favicon} alt='' title={domain} className='w-full max-h-full' />
|
<img src={account.favicon} alt='' title={account.domain} className='w-full max-h-full' />
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
|
@ -177,4 +177,18 @@ describe('normalizeAccount()', () => {
|
||||||
expect(result.staff).toBe(true);
|
expect(result.staff).toBe(true);
|
||||||
expect(result.moderator).toBe(false);
|
expect(result.moderator).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('normalizes Pleroma favicon', () => {
|
||||||
|
const account = require('soapbox/__fixtures__/pleroma-account.json');
|
||||||
|
const result = normalizeAccount(account);
|
||||||
|
|
||||||
|
expect(result.favicon).toEqual('https://gleasonator.com/favicon.png');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('adds account domain', () => {
|
||||||
|
const account = require('soapbox/__fixtures__/pleroma-account.json');
|
||||||
|
const result = normalizeAccount(account);
|
||||||
|
|
||||||
|
expect(result.domain).toEqual('gleasonator.com');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -28,6 +28,7 @@ export const AccountRecord = ImmutableRecord({
|
||||||
created_at: new Date(),
|
created_at: new Date(),
|
||||||
display_name: '',
|
display_name: '',
|
||||||
emojis: ImmutableList<Emoji>(),
|
emojis: ImmutableList<Emoji>(),
|
||||||
|
favicon: '',
|
||||||
fields: ImmutableList<Field>(),
|
fields: ImmutableList<Field>(),
|
||||||
followers_count: 0,
|
followers_count: 0,
|
||||||
following_count: 0,
|
following_count: 0,
|
||||||
|
@ -52,6 +53,7 @@ export const AccountRecord = ImmutableRecord({
|
||||||
// Internal fields
|
// Internal fields
|
||||||
admin: false,
|
admin: false,
|
||||||
display_name_html: '',
|
display_name_html: '',
|
||||||
|
domain: '',
|
||||||
moderator: false,
|
moderator: false,
|
||||||
note_emojified: '',
|
note_emojified: '',
|
||||||
note_plain: '',
|
note_plain: '',
|
||||||
|
@ -224,6 +226,16 @@ const normalizeFqn = (account: ImmutableMap<string, any>) => {
|
||||||
return account.set('fqn', fqn);
|
return account.set('fqn', fqn);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const normalizeFavicon = (account: ImmutableMap<string, any>) => {
|
||||||
|
const favicon = account.getIn(['pleroma', 'favicon']) || '';
|
||||||
|
return account.set('favicon', favicon);
|
||||||
|
};
|
||||||
|
|
||||||
|
const addDomain = (account: ImmutableMap<string, any>) => {
|
||||||
|
const domain = account.get('fqn', '').split('@')[1] || '';
|
||||||
|
return account.set('domain', domain);
|
||||||
|
};
|
||||||
|
|
||||||
const addStaffFields = (account: ImmutableMap<string, any>) => {
|
const addStaffFields = (account: ImmutableMap<string, any>) => {
|
||||||
const admin = account.getIn(['pleroma', 'is_admin']) === true;
|
const admin = account.getIn(['pleroma', 'is_admin']) === true;
|
||||||
const moderator = account.getIn(['pleroma', 'is_moderator']) === true;
|
const moderator = account.getIn(['pleroma', 'is_moderator']) === true;
|
||||||
|
@ -248,6 +260,8 @@ export const normalizeAccount = (account: Record<string, any>) => {
|
||||||
normalizeBirthday(account);
|
normalizeBirthday(account);
|
||||||
normalizeLocation(account);
|
normalizeLocation(account);
|
||||||
normalizeFqn(account);
|
normalizeFqn(account);
|
||||||
|
normalizeFavicon(account);
|
||||||
|
addDomain(account);
|
||||||
addStaffFields(account);
|
addStaffFields(account);
|
||||||
fixUsername(account);
|
fixUsername(account);
|
||||||
fixDisplayName(account);
|
fixDisplayName(account);
|
||||||
|
|
Loading…
Reference in New Issue