2020-05-17 12:44:33 -07:00
|
|
|
// Detect backend features to conditionally render elements
|
2021-08-23 12:14:47 -07:00
|
|
|
import { List as ImmutableList, Map as ImmutableMap } from 'immutable';
|
2021-07-06 11:06:21 -07:00
|
|
|
import { createSelector } from 'reselect';
|
2022-01-10 14:17:52 -08:00
|
|
|
import gte from 'semver/functions/gte';
|
|
|
|
import lt from 'semver/functions/lt';
|
2020-05-17 12:44:33 -07:00
|
|
|
|
2021-09-18 12:27:15 -07:00
|
|
|
const any = arr => arr.some(Boolean);
|
|
|
|
|
|
|
|
// For uglification
|
2021-10-05 15:39:38 -07:00
|
|
|
export const MASTODON = 'Mastodon';
|
|
|
|
export const PLEROMA = 'Pleroma';
|
2021-09-18 12:27:15 -07:00
|
|
|
|
2021-07-06 11:06:21 -07:00
|
|
|
export const getFeatures = createSelector([
|
|
|
|
instance => parseVersion(instance.get('version')),
|
|
|
|
instance => instance.getIn(['pleroma', 'metadata', 'features'], ImmutableList()),
|
2021-08-23 12:14:47 -07:00
|
|
|
instance => instance.getIn(['pleroma', 'metadata', 'federation'], ImmutableMap()),
|
|
|
|
], (v, features, federation) => {
|
2020-05-17 12:44:33 -07:00
|
|
|
return {
|
2021-09-18 12:27:15 -07:00
|
|
|
bookmarks: any([
|
|
|
|
v.software === MASTODON && gte(v.compatVersion, '3.1.0'),
|
|
|
|
v.software === PLEROMA && gte(v.version, '0.9.9'),
|
|
|
|
]),
|
2021-09-18 12:36:42 -07:00
|
|
|
lists: any([
|
|
|
|
v.software === MASTODON && gte(v.compatVersion, '2.1.0'),
|
|
|
|
v.software === PLEROMA && gte(v.version, '0.9.9'),
|
|
|
|
]),
|
2021-11-26 21:36:17 -08:00
|
|
|
suggestions: any([
|
|
|
|
v.software === MASTODON && gte(v.compatVersion, '2.4.3'),
|
|
|
|
features.includes('v2_suggestions'),
|
|
|
|
]),
|
|
|
|
suggestionsV2: any([
|
|
|
|
v.software === MASTODON && gte(v.compatVersion, '3.4.0'),
|
|
|
|
features.includes('v2_suggestions'),
|
|
|
|
]),
|
2022-01-14 17:06:31 -08:00
|
|
|
blockersVisible: features.includes('blockers_visible'),
|
2021-09-18 12:27:15 -07:00
|
|
|
trends: v.software === MASTODON && gte(v.compatVersion, '3.0.0'),
|
2021-10-05 10:59:37 -07:00
|
|
|
mediaV2: any([
|
|
|
|
v.software === MASTODON && gte(v.compatVersion, '3.1.3'),
|
2021-10-19 09:28:48 -07:00
|
|
|
// Even though Pleroma supports these endpoints, it has disadvantages
|
|
|
|
// v.software === PLEROMA && gte(v.version, '2.1.0'),
|
2021-10-05 10:59:37 -07:00
|
|
|
]),
|
2021-10-05 15:24:01 -07:00
|
|
|
directTimeline: any([
|
|
|
|
v.software === MASTODON && lt(v.compatVersion, '3.0.0'),
|
|
|
|
v.software === PLEROMA && gte(v.version, '0.9.9'),
|
|
|
|
]),
|
|
|
|
conversations: any([
|
|
|
|
v.software === MASTODON && gte(v.compatVersion, '2.6.0'),
|
|
|
|
v.software === PLEROMA && gte(v.version, '0.9.9'),
|
|
|
|
]),
|
2021-09-18 12:27:15 -07:00
|
|
|
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'),
|
2021-10-31 14:07:41 -07:00
|
|
|
importAPI: v.software === PLEROMA,
|
2021-09-18 12:27:15 -07:00
|
|
|
importMutes: v.software === PLEROMA && gte(v.version, '2.2.0'),
|
2021-08-23 12:14:47 -07:00
|
|
|
emailList: features.includes('email_list'),
|
2021-09-18 12:27:15 -07:00
|
|
|
chats: v.software === PLEROMA && gte(v.version, '2.1.0'),
|
2021-12-14 04:38:59 -08:00
|
|
|
chatsV2: v.software === PLEROMA && gte(v.version, '2.3.0'),
|
2021-09-18 12:27:15 -07:00
|
|
|
scopes: v.software === PLEROMA ? 'read write follow push admin' : 'read write follow push',
|
2021-08-23 12:14:47 -07:00
|
|
|
federating: federation.get('enabled', true), // Assume true unless explicitly false
|
2021-09-18 12:27:15 -07:00
|
|
|
richText: v.software === PLEROMA,
|
|
|
|
securityAPI: v.software === PLEROMA,
|
|
|
|
settingsStore: v.software === PLEROMA,
|
|
|
|
accountAliasesAPI: v.software === PLEROMA,
|
|
|
|
resetPasswordAPI: v.software === PLEROMA,
|
2021-09-09 11:44:12 -07:00
|
|
|
exposableReactions: features.includes('exposable_reactions'),
|
2021-09-18 12:27:15 -07:00
|
|
|
accountSubscriptions: v.software === PLEROMA && gte(v.version, '1.0.0'),
|
|
|
|
unrestrictedLists: v.software === PLEROMA,
|
2021-09-18 13:50:29 -07:00
|
|
|
accountByUsername: v.software === PLEROMA,
|
2021-12-25 09:21:20 -08:00
|
|
|
profileDirectory: any([
|
|
|
|
v.software === MASTODON && gte(v.compatVersion, '3.0.0'),
|
|
|
|
features.includes('profile_directory'),
|
|
|
|
]),
|
2021-12-29 14:54:16 -08:00
|
|
|
accountLookup: any([
|
|
|
|
v.software === MASTODON && gte(v.compatVersion, '3.4.0'),
|
|
|
|
v.software === PLEROMA && gte(v.version, '2.4.50'),
|
|
|
|
]),
|
2022-01-02 12:43:53 -08:00
|
|
|
remoteInteractionsAPI: v.software === PLEROMA && gte(v.version, '2.4.50'),
|
2022-01-04 12:06:08 -08:00
|
|
|
explicitAddressing: v.software === PLEROMA && gte(v.version, '1.0.0'),
|
2022-01-10 12:19:38 -08:00
|
|
|
accountEndorsements: v.software === PLEROMA && gte(v.version, '2.4.50'),
|
2020-05-17 12:44:33 -07:00
|
|
|
};
|
2021-07-06 11:06:21 -07:00
|
|
|
});
|
2020-05-17 12:44:33 -07:00
|
|
|
|
|
|
|
export const parseVersion = version => {
|
2021-08-03 10:10:42 -07:00
|
|
|
const regex = /^([\w\.]*)(?: \(compatible; ([\w]*) (.*)\))?$/;
|
|
|
|
const match = regex.exec(version);
|
2020-05-17 12:44:33 -07:00
|
|
|
return {
|
2021-09-18 12:27:15 -07:00
|
|
|
software: match[2] || MASTODON,
|
2020-05-17 12:44:33 -07:00
|
|
|
version: match[3] || match[1],
|
|
|
|
compatVersion: match[1],
|
|
|
|
};
|
|
|
|
};
|