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 { createSelector } from 'reselect';
|
||||||
|
|
||||||
import { getHost } from 'soapbox/actions/instance';
|
import { getHost } from 'soapbox/actions/instance';
|
||||||
import { normalizeSoapboxConfig } from 'soapbox/normalizers';
|
import { normalizeSoapboxConfig } from 'soapbox/normalizers';
|
||||||
import KVStore from 'soapbox/storage/kv_store';
|
import KVStore from 'soapbox/storage/kv_store';
|
||||||
|
import { removeVS16s } from 'soapbox/utils/emoji';
|
||||||
import { getFeatures } from 'soapbox/utils/features';
|
import { getFeatures } from 'soapbox/utils/features';
|
||||||
|
|
||||||
import api, { staticClient } from '../api';
|
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_SUCCESS = 'SOAPBOX_CONFIG_REMEMBER_SUCCESS';
|
||||||
export const SOAPBOX_CONFIG_REMEMBER_FAIL = 'SOAPBOX_CONFIG_REMEMBER_FAIL';
|
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([
|
export const getSoapboxConfig = createSelector([
|
||||||
state => state.get('soapbox'),
|
state => state.soapbox,
|
||||||
state => getFeatures(state.get('instance')),
|
state => getFeatures(state.instance),
|
||||||
], (soapbox, features) => {
|
], (soapbox, features) => {
|
||||||
const defaultConfig = makeDefaultConfig(features);
|
// Do some additional normalization with the state
|
||||||
return normalizeSoapboxConfig(soapbox).merge(defaultConfig);
|
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) {
|
export function rememberSoapboxConfig(host) {
|
||||||
|
|
|
@ -83,7 +83,7 @@ const getInstanceFeatures = (instance: Instance) => {
|
||||||
chats: v.software === PLEROMA && gte(v.version, '2.1.0'),
|
chats: v.software === PLEROMA && gte(v.version, '2.1.0'),
|
||||||
chatsV2: v.software === PLEROMA && gte(v.version, '2.3.0'),
|
chatsV2: v.software === PLEROMA && gte(v.version, '2.3.0'),
|
||||||
scopes: v.software === PLEROMA ? 'read write follow push admin' : 'read write follow push',
|
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,
|
richText: v.software === PLEROMA,
|
||||||
securityAPI: any([
|
securityAPI: any([
|
||||||
v.software === PLEROMA,
|
v.software === PLEROMA,
|
||||||
|
|
Loading…
Reference in a new issue