Add 'local' to account schema

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2023-10-22 00:14:23 +02:00
parent 0658530447
commit ba5e018e3c
12 changed files with 20 additions and 31 deletions

View file

@ -9,7 +9,6 @@ import { Stack, Text } from 'soapbox/components/ui';
import AccountContainer from 'soapbox/containers/account-container';
import { selectAccount } from 'soapbox/selectors';
import toast from 'soapbox/toast';
import { isLocal } from 'soapbox/utils/accounts';
import type { AppDispatch, RootState } from 'soapbox/store';
@ -79,7 +78,7 @@ const deleteUserModal = (intl: IntlShape, accountId: string, afterConfirm = () =
const account = selectAccount(state, accountId)!;
const acct = account.acct;
const name = account.username;
const local = isLocal(account);
const local = account.local;
const message = (
<Stack space={4}>

View file

@ -14,7 +14,6 @@ import Badge from 'soapbox/components/badge';
import ActionButton from 'soapbox/features/ui/components/action-button';
import { UserPanel } from 'soapbox/features/ui/util/async-components';
import { useAppSelector, useAppDispatch } from 'soapbox/hooks';
import { isLocal } from 'soapbox/utils/accounts';
import { showProfileHoverCard } from './hover-ref-wrapper';
import { dateFormatOptions } from './relative-timestamp';
@ -117,7 +116,7 @@ export const ProfileHoverCard: React.FC<IProfileHoverCard> = ({ visible = true }
badges={badges}
/>
{isLocal(account) ? (
{account.local ? (
<HStack alignItems='center' space={0.5}>
<Icon
src={require('@tabler/icons/calendar.svg')}

View file

@ -23,7 +23,6 @@ import { HStack } from 'soapbox/components/ui';
import { useAppDispatch, useAppSelector, useFeatures, useOwnAccount, useSettings, useSoapboxConfig } from 'soapbox/hooks';
import { GroupRoles } from 'soapbox/schemas/group-member';
import toast from 'soapbox/toast';
import { isLocal, isRemote } from 'soapbox/utils/accounts';
import copy from 'soapbox/utils/copy';
import { getReactForStatus, reduceEmoji } from 'soapbox/utils/emoji-reacts';
@ -415,7 +414,7 @@ const StatusActionBar: React.FC<IStatusActionBar> = ({
icon: require('@tabler/icons/clipboard-copy.svg'),
});
if (features.embeds && isLocal(account)) {
if (features.embeds && account.local) {
menu.push({
text: intl.formatMessage(messages.embed),
action: handleEmbed,
@ -449,7 +448,7 @@ const StatusActionBar: React.FC<IStatusActionBar> = ({
});
}
if (features.federating && isRemote(account)) {
if (features.federating && !account.local) {
menu.push({
text: intl.formatMessage(messages.external, { domain }),
action: handleExternalClick,

View file

@ -3,11 +3,10 @@ import { FormattedMessage, useIntl } from 'react-intl';
import { translateStatus, undoStatusTranslation } from 'soapbox/actions/statuses';
import { useAppDispatch, useAppSelector, useFeatures, useInstance } from 'soapbox/hooks';
import { isLocal } from 'soapbox/utils/accounts';
import { Stack, Button, Text } from './ui';
import type { Account, Status } from 'soapbox/types/entities';
import type { Status } from 'soapbox/types/entities';
interface ITranslateButton {
status: Status;
@ -28,7 +27,7 @@ const TranslateButton: React.FC<ITranslateButton> = ({ status }) => {
target_languages: targetLanguages,
} = instance.pleroma.metadata.translation;
const renderTranslate = (me || allowUnauthenticated) && (allowRemote || isLocal(status.account as Account)) && ['public', 'unlisted'].includes(status.visibility) && status.contentHtml.length > 0 && status.language !== null && intl.locale !== status.language;
const renderTranslate = (me || allowUnauthenticated) && (allowRemote || status.account.local) && ['public', 'unlisted'].includes(status.visibility) && status.contentHtml.length > 0 && status.language !== null && intl.locale !== status.language;
const supportsLanguages = (!sourceLanguages || sourceLanguages.includes(status.language!)) && (!targetLanguages || targetLanguages.includes(intl.locale));

View file

@ -28,7 +28,7 @@ import { ChatKeys, useChats } from 'soapbox/queries/chats';
import { queryClient } from 'soapbox/queries/client';
import { Account } from 'soapbox/schemas';
import toast from 'soapbox/toast';
import { isDefaultHeader, isLocal, isRemote } from 'soapbox/utils/accounts';
import { isDefaultHeader } from 'soapbox/utils/accounts';
import copy from 'soapbox/utils/copy';
import { MASTODON, parseVersion } from 'soapbox/utils/features';
@ -287,7 +287,7 @@ const Header: React.FC<IHeader> = ({ account }) => {
return [];
}
if (features.rssFeeds && isLocal(account)) {
if (features.rssFeeds && account.local) {
menu.push({
text: intl.formatMessage(messages.subscribeFeed),
action: handleRssFeedClick,
@ -303,7 +303,7 @@ const Header: React.FC<IHeader> = ({ account }) => {
});
}
if (features.federating && isRemote(account)) {
if (features.federating && !account.local) {
const domain = account.fqn.split('@')[1];
menu.push({
@ -453,7 +453,7 @@ const Header: React.FC<IHeader> = ({ account }) => {
});
}
if (isRemote(account)) {
if (!account.local) {
const domain = account.fqn.split('@')[1];
menu.push(null);

View file

@ -19,7 +19,6 @@ import { Button, HStack, IconButton, Menu, MenuButton, MenuDivider, MenuItem, Me
import SvgIcon from 'soapbox/components/ui/icon/svg-icon';
import VerificationBadge from 'soapbox/components/verification-badge';
import { useAppDispatch, useFeatures, useOwnAccount, useSettings } from 'soapbox/hooks';
import { isRemote } from 'soapbox/utils/accounts';
import copy from 'soapbox/utils/copy';
import { download } from 'soapbox/utils/download';
import { shortNumberFormat } from 'soapbox/utils/numbers';
@ -217,7 +216,7 @@ const EventHeader: React.FC<IEventHeader> = ({ status }) => {
},
];
if (features.federating && isRemote(account)) {
if (features.federating && !account.local) {
menu.push({
text: intl.formatMessage(messages.external, { domain }),
action: handleExternalClick,

View file

@ -12,7 +12,6 @@ import OutlineBox from 'soapbox/components/outline-box';
import { Button, Text, HStack, Modal, Stack, Toggle } from 'soapbox/components/ui';
import { useAppDispatch, useFeatures, useOwnAccount } from 'soapbox/hooks';
import toast from 'soapbox/toast';
import { isLocal } from 'soapbox/utils/accounts';
import { getBadges } from 'soapbox/utils/badges';
import BadgeInput from './badge-input';
@ -115,7 +114,7 @@ const AccountModerationModal: React.FC<IAccountModerationModal> = ({ onClose, ac
</OutlineBox>
<List>
{(ownAccount.admin && isLocal(account)) && (
{(ownAccount.admin && account.local) && (
<ListItem label={<FormattedMessage id='account_moderation_modal.fields.account_role' defaultMessage='Staff level' />}>
<div className='w-auto'>
<StaffRolePicker account={account} />

View file

@ -7,7 +7,7 @@ import { fetchRules } from 'soapbox/actions/rules';
import { Button, FormGroup, HStack, Stack, Text, Toggle } from 'soapbox/components/ui';
import StatusCheckBox from 'soapbox/features/report/components/status-check-box';
import { useAppDispatch, useAppSelector, useFeatures } from 'soapbox/hooks';
import { isRemote, getDomain } from 'soapbox/utils/accounts';
import { getDomain } from 'soapbox/utils/accounts';
import type { Account } from 'soapbox/schemas';
@ -31,7 +31,7 @@ const OtherActionsStep = ({ account }: IOtherActionsStep) => {
const statusIds = useAppSelector((state) => OrderedSet(state.timelines.get(`account:${account.id}:with_replies`)!.items).union(state.reports.new.status_ids) as OrderedSet<string>);
const isBlocked = useAppSelector((state) => state.reports.new.block);
const isForward = useAppSelector((state) => state.reports.new.forward);
const canForward = isRemote(account) && features.federating;
const canForward = !account.local && features.federating;
const isSubmitting = useAppSelector((state) => state.reports.new.isSubmitting);
const [showAdditionalStatuses, setShowAdditionalStatuses] = useState<boolean>(false);

View file

@ -7,7 +7,6 @@ import Markup from 'soapbox/components/markup';
import { dateFormatOptions } from 'soapbox/components/relative-timestamp';
import { Icon, HStack, Stack, Text } from 'soapbox/components/ui';
import { useAppSelector, useSoapboxConfig } from 'soapbox/hooks';
import { isLocal } from 'soapbox/utils/accounts';
import { badgeToTag, getBadges as getAccountBadges } from 'soapbox/utils/badges';
import { capitalize } from 'soapbox/utils/strings';
@ -176,7 +175,7 @@ const ProfileInfoPanel: React.FC<IProfileInfoPanel> = ({ account, username }) =>
)}
<div className='flex flex-col items-start gap-2 md:flex-row md:flex-wrap md:items-center'>
{isLocal(account) ? (
{account.local ? (
<HStack alignItems='center' space={0.5}>
<Icon
src={require('@tabler/icons/calendar.svg')}

View file

@ -17,7 +17,7 @@ import {
AccountNotePanel,
} from 'soapbox/features/ui/util/async-components';
import { useAppSelector, useFeatures, useSoapboxConfig } from 'soapbox/hooks';
import { getAcct, isLocal } from 'soapbox/utils/accounts';
import { getAcct } from 'soapbox/utils/accounts';
interface IProfilePage {
params?: {
@ -118,7 +118,7 @@ const ProfilePage: React.FC<IProfilePage> = ({ params, children }) => {
{(account && account.fields.length > 0) && (
<ProfileFieldsPanel account={account} />
)}
{(features.accountEndorsements && account && isLocal(account)) ? (
{(features.accountEndorsements && account && account.local) ? (
<PinnedAccountsPanel account={account} limit={5} />
) : me && features.suggestions && (
<WhoToFollowPanel limit={3} />

View file

@ -38,6 +38,7 @@ const baseAccountSchema = z.object({
header_static: z.string().url().optional().catch(undefined),
id: z.string(),
last_status_at: z.string().datetime().optional().catch(undefined),
local: z.boolean().catch(false),
location: z.string().optional().catch(undefined),
locked: z.boolean().catch(false),
moved: z.literal(null).catch(null),
@ -65,6 +66,7 @@ const baseAccountSchema = z.object({
hide_follows: z.boolean().catch(false),
hide_follows_count: z.boolean().catch(false),
is_admin: z.boolean().catch(false),
is_local: z.boolean().optional().catch(undefined),
is_moderator: z.boolean().catch(false),
is_suggested: z.boolean().catch(false),
location: z.string().optional().catch(undefined),
@ -134,6 +136,7 @@ const transformAccount = <T extends TransformableAccount>({ pleroma, other_setti
fqn: account.fqn || (account.acct.includes('@') ? account.acct : `${account.acct}@${domain}`),
header_static: account.header_static || account.header,
moderator: pleroma?.is_moderator || false,
local: pleroma?.is_local !== undefined ? pleroma.is_local : account.acct.split('@')[1] === undefined,
location: account.location || pleroma?.location || other_settings?.location || '',
note_emojified: emojify(account.note, customEmojiMap),
pleroma: (() => {

View file

@ -26,13 +26,6 @@ export const getAcct = (account: Pick<Account, 'fqn' | 'acct'>, displayFqn: bool
displayFqn === true ? account.fqn : account.acct
);
export const isLocal = (account: Pick<Account, 'acct'>): boolean => {
const domain: string = account.acct.split('@')[1];
return domain === undefined ? true : false;
};
export const isRemote = (account: Pick<Account, 'acct'>): boolean => !isLocal(account);
/** Default header filenames from various backends */
const DEFAULT_HEADERS: string[] = [
'/headers/original/missing.png', // Mastodon