2020-05-17 12:44:33 -07:00
|
|
|
// Detect backend features to conditionally render elements
|
2020-09-27 19:41:11 -07:00
|
|
|
import gte from 'semver/functions/gte';
|
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';
|
2020-05-17 12:44:33 -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 {
|
2020-09-27 19:41:11 -07:00
|
|
|
suggestions: v.software === 'Mastodon' && gte(v.compatVersion, '2.4.3'),
|
2021-09-16 16:46:04 -07:00
|
|
|
suggestionsV2: v.software === 'Mastodon' && gte(v.compatVersion, '3.4.0'),
|
2020-09-27 19:41:11 -07:00
|
|
|
trends: v.software === 'Mastodon' && gte(v.compatVersion, '3.0.0'),
|
|
|
|
emojiReacts: v.software === 'Pleroma' && gte(v.version, '2.0.0'),
|
2021-01-18 11:31:16 -08:00
|
|
|
emojiReactsRGI: v.software === 'Pleroma' && gte(v.version, '2.2.49'),
|
2020-06-07 12:31:04 -07:00
|
|
|
attachmentLimit: v.software === 'Pleroma' ? Infinity : 4,
|
2020-09-27 19:41:11 -07:00
|
|
|
focalPoint: v.software === 'Mastodon' && gte(v.compatVersion, '2.3.0'),
|
2021-01-07 12:26:05 -08: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-08-20 13:46:17 -07:00
|
|
|
chats: v.software === 'Pleroma' && gte(v.version, '2.1.0'),
|
2021-08-22 17:13:09 -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-08-23 13:31:42 -07:00
|
|
|
richText: v.software === 'Pleroma',
|
|
|
|
securityAPI: v.software === 'Pleroma',
|
|
|
|
settingsStore: v.software === 'Pleroma',
|
|
|
|
accountAliasesAPI: v.software === 'Pleroma',
|
2021-09-08 09:31:26 -07:00
|
|
|
resetPasswordAPI: v.software === 'Pleroma',
|
2021-09-09 11:44:12 -07:00
|
|
|
exposableReactions: features.includes('exposable_reactions'),
|
2021-09-13 10:29:34 -07:00
|
|
|
accountSubscriptions: v.software === 'Pleroma' && gte(v.version, '1.0.0'),
|
|
|
|
unrestrictedLists: v.software === 'Pleroma',
|
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 {
|
|
|
|
software: match[2] || 'Mastodon',
|
|
|
|
version: match[3] || match[1],
|
|
|
|
compatVersion: match[1],
|
|
|
|
};
|
|
|
|
};
|