Fix composer not opening for Pleroma instances

Pleroma doesn't have `configuration` in instance API response
This commit is contained in:
Lim Chee Aun 2023-10-24 14:30:50 +08:00
parent 7555bda8e9
commit 0247c041f2
2 changed files with 55 additions and 6 deletions

View file

@ -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();

View file

@ -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);
}