diff --git a/app/soapbox/actions/compose.js b/app/soapbox/actions/compose.js index 4eca355d4..11d53f317 100644 --- a/app/soapbox/actions/compose.js +++ b/app/soapbox/actions/compose.js @@ -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); diff --git a/app/soapbox/reducers/__tests__/instance-test.js b/app/soapbox/reducers/__tests__/instance-test.js index 906497926..17eae2e52 100644 --- a/app/soapbox/reducers/__tests__/instance-test.js +++ b/app/soapbox/reducers/__tests__/instance-test.js @@ -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, diff --git a/app/soapbox/reducers/instance.js b/app/soapbox/reducers/instance.js index b89ebc4ff..25a04562e 100644 --- a/app/soapbox/reducers/instance.js +++ b/app/soapbox/reducers/instance.js @@ -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']); diff --git a/app/soapbox/utils/__tests__/features-test.js b/app/soapbox/utils/__tests__/features-test.js index aec1eb1db..3e722e4ac 100644 --- a/app/soapbox/utils/__tests__/features-test.js +++ b/app/soapbox/utils/__tests__/features-test.js @@ -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' }); diff --git a/app/soapbox/utils/features.js b/app/soapbox/utils/features.js index fc3dc68ab..fac905130 100644 --- a/app/soapbox/utils/features.js +++ b/app/soapbox/utils/features.js @@ -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'),