2020-04-01 12:38:08 -07:00
|
|
|
import api from '../api';
|
2020-08-23 13:56:18 -07:00
|
|
|
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
2021-01-18 11:31:16 -08:00
|
|
|
import { getFeatures } from 'soapbox/utils/features';
|
2020-04-01 12:38:08 -07:00
|
|
|
|
2020-06-03 12:24:53 -07:00
|
|
|
export const SOAPBOX_CONFIG_REQUEST_SUCCESS = 'SOAPBOX_CONFIG_REQUEST_SUCCESS';
|
|
|
|
export const SOAPBOX_CONFIG_REQUEST_FAIL = 'SOAPBOX_CONFIG_REQUEST_FAIL';
|
2020-04-01 12:38:08 -07:00
|
|
|
|
2021-01-18 11:31:16 -08:00
|
|
|
const allowedEmoji = ImmutableList([
|
|
|
|
'👍',
|
|
|
|
'❤',
|
|
|
|
'😆',
|
|
|
|
'😮',
|
|
|
|
'😢',
|
|
|
|
'😩',
|
|
|
|
]);
|
|
|
|
|
|
|
|
// https://git.pleroma.social/pleroma/pleroma/-/issues/2355
|
|
|
|
const allowedEmojiRGI = ImmutableList([
|
|
|
|
'👍',
|
|
|
|
'❤️',
|
|
|
|
'😆',
|
|
|
|
'😮',
|
|
|
|
'😢',
|
|
|
|
'😩',
|
|
|
|
]);
|
|
|
|
|
2020-08-23 18:29:29 -07:00
|
|
|
export const defaultConfig = ImmutableMap({
|
2020-08-23 13:56:18 -07:00
|
|
|
logo: '',
|
|
|
|
banner: '',
|
2020-08-31 20:00:11 -07:00
|
|
|
brandColor: '', // Empty
|
2020-08-23 13:56:18 -07:00
|
|
|
customCss: ImmutableList(),
|
|
|
|
promoPanel: ImmutableMap({
|
|
|
|
items: ImmutableList(),
|
|
|
|
}),
|
|
|
|
extensions: ImmutableMap(),
|
|
|
|
defaultSettings: ImmutableMap(),
|
|
|
|
copyright: '♥2020. Copying is an act of love. Please copy and share.',
|
|
|
|
navlinks: ImmutableMap({
|
|
|
|
homeFooter: ImmutableList(),
|
|
|
|
}),
|
2021-01-18 11:31:16 -08:00
|
|
|
allowedEmoji: allowedEmoji,
|
2020-08-23 13:56:18 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
export function getSoapboxConfig(state) {
|
2021-01-18 11:31:16 -08:00
|
|
|
const instance = state.get('instance');
|
|
|
|
const soapbox = state.get('soapbox');
|
|
|
|
const features = getFeatures(instance);
|
|
|
|
|
|
|
|
// https://git.pleroma.social/pleroma/pleroma/-/issues/2355
|
|
|
|
if (features.emojiReactsRGI) {
|
|
|
|
return defaultConfig
|
|
|
|
.set('allowedEmoji', allowedEmojiRGI)
|
|
|
|
.merge(soapbox);
|
|
|
|
} else {
|
|
|
|
return defaultConfig.merge(soapbox);
|
|
|
|
}
|
2020-08-23 13:56:18 -07:00
|
|
|
}
|
|
|
|
|
2020-04-01 12:38:08 -07:00
|
|
|
export function fetchSoapboxConfig() {
|
|
|
|
return (dispatch, getState) => {
|
2020-07-25 16:27:39 -07:00
|
|
|
api(getState).get('/api/pleroma/frontend_configurations').then(response => {
|
|
|
|
if (response.data.soapbox_fe) {
|
|
|
|
dispatch(importSoapboxConfig(response.data.soapbox_fe));
|
|
|
|
} else {
|
2020-08-23 13:32:44 -07:00
|
|
|
dispatch(fetchSoapboxJson());
|
2020-07-25 16:27:39 -07:00
|
|
|
}
|
2020-04-01 12:38:08 -07:00
|
|
|
}).catch(error => {
|
2020-08-23 13:32:44 -07:00
|
|
|
dispatch(fetchSoapboxJson());
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function fetchSoapboxJson() {
|
|
|
|
return (dispatch, getState) => {
|
2020-08-31 22:02:01 -07:00
|
|
|
api(getState).get('/instance/soapbox.json').then(({ data }) => {
|
|
|
|
if (!isObject(data)) throw 'soapbox.json failed';
|
|
|
|
dispatch(importSoapboxConfig(data));
|
2020-08-23 13:32:44 -07:00
|
|
|
}).catch(error => {
|
|
|
|
dispatch(soapboxConfigFail(error));
|
2020-04-01 12:38:08 -07:00
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function importSoapboxConfig(soapboxConfig) {
|
2020-09-02 19:47:46 -07:00
|
|
|
if (!soapboxConfig.brandColor) {
|
|
|
|
soapboxConfig.brandColor = '#0482d8';
|
2020-08-31 20:00:11 -07:00
|
|
|
};
|
2020-04-01 12:38:08 -07:00
|
|
|
return {
|
2020-06-03 12:24:53 -07:00
|
|
|
type: SOAPBOX_CONFIG_REQUEST_SUCCESS,
|
2020-04-14 11:44:40 -07:00
|
|
|
soapboxConfig,
|
2020-04-01 12:38:08 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function soapboxConfigFail(error) {
|
|
|
|
return {
|
2020-06-03 12:24:53 -07:00
|
|
|
type: SOAPBOX_CONFIG_REQUEST_FAIL,
|
2020-04-01 12:38:08 -07:00
|
|
|
error,
|
|
|
|
skipAlert: true,
|
|
|
|
};
|
2020-06-09 16:53:35 -07:00
|
|
|
}
|
2020-08-31 22:02:01 -07:00
|
|
|
|
|
|
|
// https://stackoverflow.com/a/46663081
|
|
|
|
function isObject(o) {
|
|
|
|
return o instanceof Object && o.constructor === Object;
|
|
|
|
}
|