-
diff --git a/app/soapbox/features/soapbox_config/index.js b/app/soapbox/features/soapbox_config/index.js
index 37b3dd1fb..7856a8027 100644
--- a/app/soapbox/features/soapbox_config/index.js
+++ b/app/soapbox/features/soapbox_config/index.js
@@ -14,7 +14,7 @@ import {
FormPropTypes,
} from 'soapbox/features/forms';
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
-import { updateAdminConfig } from 'soapbox/actions/admin';
+import { updateConfig } from 'soapbox/actions/admin';
import Icon from 'soapbox/components/icon';
import { defaultConfig } from 'soapbox/actions/soapbox';
import { uploadMedia } from 'soapbox/actions/media';
@@ -82,20 +82,18 @@ class SoapboxConfig extends ImmutablePureComponent {
getParams = () => {
const { soapbox } = this.state;
- return {
- configs: [{
- group: ':pleroma',
- key: ':frontend_configurations',
- value: [{
- tuple: [':soapbox_fe', soapbox.toJS()],
- }],
+ return [{
+ group: ':pleroma',
+ key: ':frontend_configurations',
+ value: [{
+ tuple: [':soapbox_fe', soapbox.toJS()],
}],
- };
+ }];
}
handleSubmit = (event) => {
const { dispatch } = this.props;
- dispatch(updateAdminConfig(this.getParams())).then(() => {
+ dispatch(updateConfig(this.getParams())).then(() => {
this.setState({ isLoading: false });
}).catch((error) => {
this.setState({ isLoading: false });
diff --git a/app/soapbox/reducers/instance.js b/app/soapbox/reducers/instance.js
index 3bcd1c4ba..68d50f116 100644
--- a/app/soapbox/reducers/instance.js
+++ b/app/soapbox/reducers/instance.js
@@ -3,7 +3,9 @@ import {
NODEINFO_FETCH_SUCCESS,
} from '../actions/instance';
import { PRELOAD_IMPORT } from 'soapbox/actions/preload';
-import { Map as ImmutableMap, fromJS } from 'immutable';
+import { ADMIN_CONFIG_UPDATE_SUCCESS } from 'soapbox/actions/admin';
+import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
+import { ConfigDB } from 'soapbox/utils/config_db';
const nodeinfoToInstance = nodeinfo => {
// Match Pleroma's develop branch
@@ -37,6 +39,27 @@ const preloadImport = (state, action, path) => {
return data ? initialState.mergeDeep(fromJS(data)) : state;
};
+const getConfigValue = (instanceConfig, key) => {
+ return instanceConfig
+ .find(value => value.getIn(['tuple', 0]) === key)
+ .getIn(['tuple', 1]);
+};
+
+const importConfigs = (state, configs) => {
+ // FIXME: This is pretty hacked together. Need to make a cleaner map.
+ const config = ConfigDB.find(configs, ':pleroma', ':instance');
+ if (!config) return state;
+ const value = config.get('value', ImmutableList());
+
+ return state.withMutations(state => {
+ const registrationsOpen = getConfigValue(value, ':registrations_open');
+ const approvalRequired = getConfigValue(value, ':account_approval_required');
+
+ state.update('registrations', c => typeof registrationsOpen === 'boolean' ? registrationsOpen : c);
+ state.update('approval_required', c => typeof approvalRequired === 'boolean' ? approvalRequired : c);
+ });
+};
+
export default function instance(state = initialState, action) {
switch(action.type) {
case PRELOAD_IMPORT:
@@ -45,6 +68,8 @@ export default function instance(state = initialState, action) {
return initialState.mergeDeep(fromJS(action.instance));
case NODEINFO_FETCH_SUCCESS:
return nodeinfoToInstance(fromJS(action.nodeinfo)).mergeDeep(state);
+ case ADMIN_CONFIG_UPDATE_SUCCESS:
+ return importConfigs(state, fromJS(action.configs));
default:
return state;
}
diff --git a/app/soapbox/reducers/soapbox.js b/app/soapbox/reducers/soapbox.js
index 40e65c608..5b7db02a8 100644
--- a/app/soapbox/reducers/soapbox.js
+++ b/app/soapbox/reducers/soapbox.js
@@ -4,7 +4,7 @@ import {
SOAPBOX_CONFIG_REQUEST_FAIL,
} from '../actions/soapbox';
import { PRELOAD_IMPORT } from 'soapbox/actions/preload';
-import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
+import { Map as ImmutableMap, fromJS } from 'immutable';
import { ConfigDB } from 'soapbox/utils/config_db';
const initialState = ImmutableMap();
@@ -13,9 +13,7 @@ const fallbackState = ImmutableMap({
brandColor: '#0482d8', // Azure
});
-const updateFromAdmin = (state, config) => {
- const configs = config.get('configs', ImmutableList());
-
+const updateFromAdmin = (state, configs) => {
try {
return ConfigDB.find(configs, ':pleroma', ':frontend_configurations')
.get('value')
@@ -47,7 +45,7 @@ export default function soapbox(state = initialState, action) {
case SOAPBOX_CONFIG_REQUEST_FAIL:
return fallbackState.mergeDeep(state);
case ADMIN_CONFIG_UPDATE_SUCCESS:
- return updateFromAdmin(state, fromJS(action.config));
+ return updateFromAdmin(state, fromJS(action.configs));
default:
return state;
}