Perform better normalization of allowedEmoji
This commit is contained in:
parent
54d76d6b56
commit
1466a08193
3 changed files with 37 additions and 32 deletions
19
app/soapbox/actions/__tests__/soapbox.test.ts
Normal file
19
app/soapbox/actions/__tests__/soapbox.test.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { rootState } from '../../jest/test-helpers';
|
||||
import { getSoapboxConfig } from '../soapbox';
|
||||
|
||||
const ASCII_HEART = '❤'; // '\u2764\uFE0F'
|
||||
const RED_HEART_RGI = '❤️'; // '\u2764'
|
||||
|
||||
describe('getSoapboxConfig()', () => {
|
||||
it('returns RGI heart on Pleroma > 2.3', () => {
|
||||
const state = rootState.setIn(['instance', 'version'], '2.7.2 (compatible; Pleroma 2.3.0)');
|
||||
expect(getSoapboxConfig(state).allowedEmoji.includes(RED_HEART_RGI)).toBe(true);
|
||||
expect(getSoapboxConfig(state).allowedEmoji.includes(ASCII_HEART)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns an ASCII heart on Pleroma < 2.3', () => {
|
||||
const state = rootState.setIn(['instance', 'version'], '2.7.2 (compatible; Pleroma 2.0.0)');
|
||||
expect(getSoapboxConfig(state).allowedEmoji.includes(ASCII_HEART)).toBe(true);
|
||||
expect(getSoapboxConfig(state).allowedEmoji.includes(RED_HEART_RGI)).toBe(false);
|
||||
});
|
||||
});
|
|
@ -1,9 +1,9 @@
|
|||
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
||||
import { createSelector } from 'reselect';
|
||||
|
||||
import { getHost } from 'soapbox/actions/instance';
|
||||
import { normalizeSoapboxConfig } from 'soapbox/normalizers';
|
||||
import KVStore from 'soapbox/storage/kv_store';
|
||||
import { removeVS16s } from 'soapbox/utils/emoji';
|
||||
import { getFeatures } from 'soapbox/utils/features';
|
||||
|
||||
import api, { staticClient } from '../api';
|
||||
|
@ -15,38 +15,24 @@ export const SOAPBOX_CONFIG_REMEMBER_REQUEST = 'SOAPBOX_CONFIG_REMEMBER_REQUEST'
|
|||
export const SOAPBOX_CONFIG_REMEMBER_SUCCESS = 'SOAPBOX_CONFIG_REMEMBER_SUCCESS';
|
||||
export const SOAPBOX_CONFIG_REMEMBER_FAIL = 'SOAPBOX_CONFIG_REMEMBER_FAIL';
|
||||
|
||||
const allowedEmoji = ImmutableList([
|
||||
'👍',
|
||||
'❤',
|
||||
'😆',
|
||||
'😮',
|
||||
'😢',
|
||||
'😩',
|
||||
]);
|
||||
|
||||
// https://git.pleroma.social/pleroma/pleroma/-/issues/2355
|
||||
const allowedEmojiRGI = ImmutableList([
|
||||
'👍',
|
||||
'❤️',
|
||||
'😆',
|
||||
'😮',
|
||||
'😢',
|
||||
'😩',
|
||||
]);
|
||||
|
||||
export const makeDefaultConfig = features => {
|
||||
return ImmutableMap({
|
||||
allowedEmoji: features.emojiReactsRGI ? allowedEmojiRGI : allowedEmoji,
|
||||
displayFqn: Boolean(features.federating),
|
||||
});
|
||||
};
|
||||
|
||||
export const getSoapboxConfig = createSelector([
|
||||
state => state.get('soapbox'),
|
||||
state => getFeatures(state.get('instance')),
|
||||
state => state.soapbox,
|
||||
state => getFeatures(state.instance),
|
||||
], (soapbox, features) => {
|
||||
const defaultConfig = makeDefaultConfig(features);
|
||||
return normalizeSoapboxConfig(soapbox).merge(defaultConfig);
|
||||
// Do some additional normalization with the state
|
||||
return normalizeSoapboxConfig(soapbox).withMutations(soapboxConfig => {
|
||||
|
||||
// If displayFqn isn't set, infer it from federation
|
||||
if (soapbox.get('displayFqn') === undefined) {
|
||||
soapboxConfig.set('displayFqn', features.federating);
|
||||
}
|
||||
|
||||
// If RGI reacts aren't supported, strip VS16s
|
||||
// // https://git.pleroma.social/pleroma/pleroma/-/issues/2355
|
||||
if (!features.emojiReactsRGI) {
|
||||
soapboxConfig.set('allowedEmoji', soapboxConfig.allowedEmoji.map(emoji => removeVS16s(emoji)));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
export function rememberSoapboxConfig(host) {
|
||||
|
|
|
@ -83,7 +83,7 @@ const getInstanceFeatures = (instance: Instance) => {
|
|||
chats: v.software === PLEROMA && gte(v.version, '2.1.0'),
|
||||
chatsV2: v.software === PLEROMA && gte(v.version, '2.3.0'),
|
||||
scopes: v.software === PLEROMA ? 'read write follow push admin' : 'read write follow push',
|
||||
federating: federation.get('enabled', true), // Assume true unless explicitly false
|
||||
federating: federation.get('enabled', true) === true, // Assume true unless explicitly false
|
||||
richText: v.software === PLEROMA,
|
||||
securityAPI: any([
|
||||
v.software === PLEROMA,
|
||||
|
|
Loading…
Reference in a new issue