Features: add Bookmarks, improve uglification

This commit is contained in:
Alex Gleason 2021-09-18 14:27:15 -05:00
parent ba0ca0e5a1
commit 46737a5468
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -3,32 +3,42 @@ import gte from 'semver/functions/gte';
import { List as ImmutableList, Map as ImmutableMap } from 'immutable'; import { List as ImmutableList, Map as ImmutableMap } from 'immutable';
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
const any = arr => arr.some(Boolean);
// For uglification
const MASTODON = 'Mastodon';
const PLEROMA = 'Pleroma';
export const getFeatures = createSelector([ export const getFeatures = createSelector([
instance => parseVersion(instance.get('version')), instance => parseVersion(instance.get('version')),
instance => instance.getIn(['pleroma', 'metadata', 'features'], ImmutableList()), instance => instance.getIn(['pleroma', 'metadata', 'features'], ImmutableList()),
instance => instance.getIn(['pleroma', 'metadata', 'federation'], ImmutableMap()), instance => instance.getIn(['pleroma', 'metadata', 'federation'], ImmutableMap()),
], (v, features, federation) => { ], (v, features, federation) => {
return { return {
suggestions: v.software === 'Mastodon' && gte(v.compatVersion, '2.4.3'), bookmarks: any([
suggestionsV2: v.software === 'Mastodon' && gte(v.compatVersion, '3.4.0'), v.software === MASTODON && gte(v.compatVersion, '3.1.0'),
trends: v.software === 'Mastodon' && gte(v.compatVersion, '3.0.0'), v.software === PLEROMA && gte(v.version, '0.9.9'),
emojiReacts: v.software === 'Pleroma' && gte(v.version, '2.0.0'), ]),
emojiReactsRGI: v.software === 'Pleroma' && gte(v.version, '2.2.49'), suggestions: v.software === MASTODON && gte(v.compatVersion, '2.4.3'),
attachmentLimit: v.software === 'Pleroma' ? Infinity : 4, suggestionsV2: v.software === MASTODON && gte(v.compatVersion, '3.4.0'),
focalPoint: v.software === 'Mastodon' && gte(v.compatVersion, '2.3.0'), trends: v.software === MASTODON && gte(v.compatVersion, '3.0.0'),
importMutes: v.software === 'Pleroma' && gte(v.version, '2.2.0'), 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'),
importMutes: v.software === PLEROMA && gte(v.version, '2.2.0'),
emailList: features.includes('email_list'), emailList: features.includes('email_list'),
chats: v.software === 'Pleroma' && gte(v.version, '2.1.0'), chats: v.software === PLEROMA && gte(v.version, '2.1.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), // Assume true unless explicitly false
richText: v.software === 'Pleroma', richText: v.software === PLEROMA,
securityAPI: v.software === 'Pleroma', securityAPI: v.software === PLEROMA,
settingsStore: v.software === 'Pleroma', settingsStore: v.software === PLEROMA,
accountAliasesAPI: v.software === 'Pleroma', accountAliasesAPI: v.software === PLEROMA,
resetPasswordAPI: v.software === 'Pleroma', resetPasswordAPI: v.software === PLEROMA,
exposableReactions: features.includes('exposable_reactions'), exposableReactions: features.includes('exposable_reactions'),
accountSubscriptions: v.software === 'Pleroma' && gte(v.version, '1.0.0'), accountSubscriptions: v.software === PLEROMA && gte(v.version, '1.0.0'),
unrestrictedLists: v.software === 'Pleroma', unrestrictedLists: v.software === PLEROMA,
}; };
}); });
@ -36,7 +46,7 @@ export const parseVersion = version => {
const regex = /^([\w\.]*)(?: \(compatible; ([\w]*) (.*)\))?$/; const regex = /^([\w\.]*)(?: \(compatible; ([\w]*) (.*)\))?$/;
const match = regex.exec(version); const match = regex.exec(version);
return { return {
software: match[2] || 'Mastodon', software: match[2] || MASTODON,
version: match[3] || match[1], version: match[3] || match[1],
compatVersion: match[1], compatVersion: match[1],
}; };