From 0247c041f20151b56ce5b5def03cab9eb0e98cb1 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Tue, 24 Oct 2023 14:30:50 +0800 Subject: [PATCH] Fix composer not opening for Pleroma instances Pleroma doesn't have `configuration` in instance API response --- src/components/compose.jsx | 22 +++++++++++++++------ src/utils/store-utils.js | 39 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/components/compose.jsx b/src/components/compose.jsx index 5a1f47c7..73de42c7 100644 --- a/src/components/compose.jsx +++ b/src/components/compose.jsx @@ -23,6 +23,7 @@ import { getCurrentAccount, getCurrentAccountNS, getCurrentInstance, + getCurrentInstanceConfiguration, } from '../utils/store-utils'; import supports from '../utils/supports'; import useInterval from '../utils/useInterval'; @@ -119,21 +120,30 @@ function Compose({ const currentAccount = getCurrentAccount(); const currentAccountInfo = currentAccount.info; - const { configuration } = getCurrentInstance(); + const configuration = getCurrentInstanceConfiguration(); console.log('⚙️ Configuration', configuration); const { - statuses: { maxCharacters, maxMediaAttachments, charactersReservedPerUrl }, + statuses: { + maxCharacters, + maxMediaAttachments, + charactersReservedPerUrl, + } = {}, mediaAttachments: { - supportedMimeTypes, + supportedMimeTypes = [], imageSizeLimit, imageMatrixLimit, videoSizeLimit, videoMatrixLimit, videoFrameRateLimit, - }, - polls: { maxOptions, maxCharactersPerOption, maxExpiration, minExpiration }, - } = configuration; + } = {}, + polls: { + maxOptions, + maxCharactersPerOption, + maxExpiration, + minExpiration, + } = {}, + } = configuration || {}; const textareaRef = useRef(); const spoilerTextRef = useRef(); diff --git a/src/utils/store-utils.js b/src/utils/store-utils.js index 6ea170b7..3c365efc 100644 --- a/src/utils/store-utils.js +++ b/src/utils/store-utils.js @@ -81,3 +81,42 @@ export function getCurrentInstance() { return {}; } } + +// Massage these instance configurations to match the Mastodon API +// - Pleroma +function getInstanceConfiguration(instance) { + const { + configuration, + maxMediaAttachments, + maxTootChars, + pleroma, + pollLimits, + } = instance; + + const statuses = configuration?.statuses || {}; + if (maxMediaAttachments) { + statuses.maxMediaAttachments ??= maxMediaAttachments; + } + if (maxTootChars) { + statuses.maxCharacters ??= maxTootChars; + } + + const polls = configuration?.polls || {}; + if (pollLimits) { + polls.maxCharactersPerOption ??= pollLimits.maxOptionChars; + polls.maxExpiration ??= pollLimits.maxExpiration; + polls.maxOptions ??= pollLimits.maxOptions; + polls.minExpiration ??= pollLimits.minExpiration; + } + + return { + ...configuration, + statuses, + polls, + }; +} + +export function getCurrentInstanceConfiguration() { + const instance = getCurrentInstance(); + return getInstanceConfiguration(instance); +}