bigbuffet-rw/app/soapbox/utils/features.js

31 lines
1.2 KiB
JavaScript
Raw Normal View History

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';
import { List as ImmutableList } from 'immutable';
import { createSelector } from 'reselect';
2020-05-17 12:44:33 -07:00
export const getFeatures = createSelector([
instance => parseVersion(instance.get('version')),
instance => instance.getIn(['pleroma', 'metadata', 'features'], ImmutableList()),
], (v, f) => {
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'),
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'),
emailList: f.includes('email_list'),
2020-05-17 12:44:33 -07:00
};
});
2020-05-17 12:44:33 -07:00
export const parseVersion = version => {
let regex = /^([\w\.]*)(?: \(compatible; ([\w]*) (.*)\))?$/;
let match = regex.exec(version);
return {
software: match[2] || 'Mastodon',
version: match[3] || match[1],
compatVersion: match[1],
};
};