sforkowany z mirror/soapbox
Set attachment limit from instance
rodzic
04979486e8
commit
e04e75f831
|
@ -296,8 +296,7 @@ export function submitComposeFail(error) {
|
|||
export function uploadCompose(files) {
|
||||
return function(dispatch, getState) {
|
||||
if (!isLoggedIn(getState)) return;
|
||||
const instance = getState().get('instance');
|
||||
const { attachmentLimit } = getFeatures(instance);
|
||||
const attachmentLimit = getState().getIn(['instance', 'configuration', 'statuses', 'max_media_attachments']);
|
||||
|
||||
const media = getState().getIn(['compose', 'media_attachments']);
|
||||
const progress = new Array(files.length).fill(0);
|
||||
|
|
|
@ -11,6 +11,7 @@ describe('instance reducer', () => {
|
|||
configuration: ImmutableMap({
|
||||
statuses: ImmutableMap({
|
||||
max_characters: 500,
|
||||
max_media_attachments: 4,
|
||||
}),
|
||||
polls: ImmutableMap({
|
||||
max_options: 4,
|
||||
|
@ -36,6 +37,7 @@ describe('instance reducer', () => {
|
|||
configuration: {
|
||||
statuses: {
|
||||
max_characters: 5000,
|
||||
max_media_attachments: Infinity,
|
||||
},
|
||||
polls: {
|
||||
max_options: 20,
|
||||
|
@ -95,6 +97,7 @@ describe('instance reducer', () => {
|
|||
configuration: {
|
||||
statuses: {
|
||||
max_characters: 500,
|
||||
max_media_attachments: 4,
|
||||
},
|
||||
polls: {
|
||||
max_options: 4,
|
||||
|
|
|
@ -4,6 +4,8 @@ import { ADMIN_CONFIG_UPDATE_REQUEST, ADMIN_CONFIG_UPDATE_SUCCESS } from 'soapbo
|
|||
import { PLEROMA_PRELOAD_IMPORT } from 'soapbox/actions/preload';
|
||||
import KVStore from 'soapbox/storage/kv_store';
|
||||
import { ConfigDB } from 'soapbox/utils/config_db';
|
||||
import { parseVersion, PLEROMA } from 'soapbox/utils/features';
|
||||
import { isNumber } from 'soapbox/utils/numbers';
|
||||
|
||||
import {
|
||||
INSTANCE_REMEMBER_SUCCESS,
|
||||
|
@ -34,6 +36,7 @@ const initialState = ImmutableMap({
|
|||
configuration: ImmutableMap({
|
||||
statuses: ImmutableMap({
|
||||
max_characters: 500,
|
||||
max_media_attachments: 4,
|
||||
}),
|
||||
polls: ImmutableMap({
|
||||
max_options: 4,
|
||||
|
@ -63,8 +66,12 @@ const pleromaToMastodonConfig = instance => {
|
|||
// Use new value only if old value is undefined
|
||||
const mergeDefined = (oldVal, newVal) => oldVal === undefined ? newVal : oldVal;
|
||||
|
||||
// Get the software's default attachment limit
|
||||
const getAttachmentLimit = software => software === PLEROMA ? Infinity : 4;
|
||||
|
||||
// Normalize instance (Pleroma, Mastodon, etc.) to Mastodon's format
|
||||
const normalizeInstance = instance => {
|
||||
const { software } = parseVersion(instance.get('version'));
|
||||
const mastodonConfig = pleromaToMastodonConfig(instance);
|
||||
|
||||
return instance.withMutations(instance => {
|
||||
|
@ -73,6 +80,11 @@ const normalizeInstance = instance => {
|
|||
configuration.mergeDeepWith(mergeDefined, mastodonConfig)
|
||||
));
|
||||
|
||||
// If max attachments isn't set, check the backend software
|
||||
instance.updateIn(['configuration', 'statuses', 'max_media_attachments'], value => {
|
||||
return isNumber(value) ? value : getAttachmentLimit(software);
|
||||
});
|
||||
|
||||
// Merge defaults & cleanup
|
||||
instance.mergeDeepWith(mergeDefined, initialState);
|
||||
instance.deleteAll(['max_toot_chars', 'poll_limits']);
|
||||
|
|
|
@ -94,22 +94,6 @@ describe('getFeatures', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('attachmentLimit', () => {
|
||||
it('is 4 by default', () => {
|
||||
const instance = ImmutableMap({ version: '3.1.4' });
|
||||
const features = getFeatures(instance);
|
||||
expect(features.attachmentLimit).toEqual(4);
|
||||
});
|
||||
|
||||
it('is Infinity for Pleroma', () => {
|
||||
const instance = ImmutableMap({
|
||||
version: '2.7.2 (compatible; Pleroma 1.1.50-42-g3d9ac6ae-develop)',
|
||||
});
|
||||
const features = getFeatures(instance);
|
||||
expect(features.attachmentLimit).toEqual(Infinity);
|
||||
});
|
||||
});
|
||||
|
||||
describe('focalPoint', () => {
|
||||
it('is true for Mastodon 2.3.0+', () => {
|
||||
const instance = ImmutableMap({ version: '2.3.0' });
|
||||
|
|
|
@ -49,7 +49,6 @@ export const getFeatures = createSelector([
|
|||
]),
|
||||
emojiReacts: v.software === PLEROMA && gte(v.version, '2.0.0'),
|
||||
emojiReactsRGI: v.software === PLEROMA && gte(v.version, '2.2.49'),
|
||||
attachmentLimit: v.software === PLEROMA ? Infinity : 4,
|
||||
focalPoint: v.software === MASTODON && gte(v.compatVersion, '2.3.0'),
|
||||
importAPI: v.software === PLEROMA,
|
||||
importMutes: v.software === PLEROMA && gte(v.version, '2.2.0'),
|
||||
|
|
Ładowanie…
Reference in New Issue