From d30d276a0f88d4199bbbb9fb5a07c27d939901b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Fri, 17 May 2024 23:30:57 +0200 Subject: [PATCH] Only display HTML if supported MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- .../components/content-type-button.tsx | 23 +++++++++++-------- src/schemas/instance.ts | 1 + 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/features/compose/components/content-type-button.tsx b/src/features/compose/components/content-type-button.tsx index c5773b5c1..50b9a2403 100644 --- a/src/features/compose/components/content-type-button.tsx +++ b/src/features/compose/components/content-type-button.tsx @@ -4,7 +4,7 @@ import { defineMessages, useIntl } from 'react-intl'; import { changeComposeContentType } from 'soapbox/actions/compose'; import DropdownMenu from 'soapbox/components/dropdown-menu'; import { Button } from 'soapbox/components/ui'; -import { useAppDispatch, useCompose } from 'soapbox/hooks'; +import { useAppDispatch, useCompose, useInstance } from 'soapbox/hooks'; const messages = defineMessages({ content_type_plaintext: { id: 'preferences.options.content_type_plaintext', defaultMessage: 'Plain text' }, @@ -21,6 +21,7 @@ interface IContentTypeButton { const ContentTypeButton: React.FC = ({ composeId }) => { const intl = useIntl(); const dispatch = useAppDispatch(); + const instance = useInstance(); const contentType = useCompose(composeId).content_type; @@ -36,17 +37,21 @@ const ContentTypeButton: React.FC = ({ composeId }) => { text: intl.formatMessage(messages.content_type_markdown), value: 'text/markdown', }, - { + ]; + + if (instance.pleroma.metadata.post_formats?.includes('text/html')) { + options.push({ icon: require('@tabler/icons/outline/html.svg'), text: intl.formatMessage(messages.content_type_html), value: 'text/html', - }, - { - icon: require('@tabler/icons/outline/text-caption.svg'), - text: intl.formatMessage(messages.content_type_wysiwyg), - value: 'wysiwyg', - }, - ]; + }); + } + + options.push({ + icon: require('@tabler/icons/outline/text-caption.svg'), + text: intl.formatMessage(messages.content_type_wysiwyg), + value: 'wysiwyg', + }); const option = options.find(({ value }) => value === contentType); diff --git a/src/schemas/instance.ts b/src/schemas/instance.ts index 9887c5725..4082dd06b 100644 --- a/src/schemas/instance.ts +++ b/src/schemas/instance.ts @@ -114,6 +114,7 @@ const pleromaSchema = coerceObject({ .optional(), enabled: z.boolean().catch(false), }), + post_formats: z.string().array().optional().catch(undefined), restrict_unauthenticated: coerceObject({ activities: coerceObject({ local: z.boolean().catch(false),