Add backend feature checks, fixes #8
This commit is contained in:
parent
ac6d25f5c7
commit
269d48c900
4 changed files with 128 additions and 3 deletions
95
app/gabsocial/utils/__tests__/features-test.js
Normal file
95
app/gabsocial/utils/__tests__/features-test.js
Normal file
|
@ -0,0 +1,95 @@
|
|||
import {
|
||||
parseVersion,
|
||||
getFeatures,
|
||||
} from '../features';
|
||||
import { fromJS } from 'immutable';
|
||||
|
||||
describe('parseVersion', () => {
|
||||
it('with Pleroma version string', () => {
|
||||
let version = '2.7.2 (compatible; Pleroma 2.0.5-6-ga36eb5ea-plerasstodon+dev)';
|
||||
expect(parseVersion(version)).toEqual({
|
||||
software: 'Pleroma',
|
||||
version: '2.0.5-6-ga36eb5ea-plerasstodon+dev',
|
||||
compatVersion: '2.7.2',
|
||||
});
|
||||
});
|
||||
|
||||
it('with Mastodon version string', () => {
|
||||
let version = '3.0.0';
|
||||
expect(parseVersion(version)).toEqual({
|
||||
software: 'Mastodon',
|
||||
version: '3.0.0',
|
||||
compatVersion: '3.0.0',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getFeatures', () => {
|
||||
describe('emojiReacts', () => {
|
||||
it('is true for Pleroma 2.0+', () => {
|
||||
let instance = fromJS({
|
||||
version: '2.7.2 (compatible; Pleroma 2.0.5-6-ga36eb5ea-plerasstodon+dev)',
|
||||
});
|
||||
let features = getFeatures(instance);
|
||||
expect(features.emojiReacts).toBe(true);
|
||||
});
|
||||
|
||||
it('is false for Pleroma < 2.0', () => {
|
||||
let instance = fromJS({
|
||||
version: '2.7.2 (compatible; Pleroma 1.1.50-42-g3d9ac6ae-develop)',
|
||||
});
|
||||
let features = getFeatures(instance);
|
||||
expect(features.emojiReacts).toBe(false);
|
||||
});
|
||||
|
||||
it('is false for Mastodon', () => {
|
||||
let instance = fromJS({ version: '3.1.4' });
|
||||
let features = getFeatures(instance);
|
||||
expect(features.emojiReacts).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('suggestions', () => {
|
||||
it('is true for Mastodon 2.4.3+', () => {
|
||||
let instance = fromJS({ version: '2.4.3' });
|
||||
let features = getFeatures(instance);
|
||||
expect(features.suggestions).toBe(true);
|
||||
});
|
||||
|
||||
it('is false for Mastodon < 2.4.3', () => {
|
||||
let instance = fromJS({ version: '2.4.2' });
|
||||
let features = getFeatures(instance);
|
||||
expect(features.suggestions).toBe(false);
|
||||
});
|
||||
|
||||
it('is false for Pleroma', () => {
|
||||
let instance = fromJS({
|
||||
version: '2.7.2 (compatible; Pleroma 1.1.50-42-g3d9ac6ae-develop)',
|
||||
});
|
||||
let features = getFeatures(instance);
|
||||
expect(features.suggestions).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('trends', () => {
|
||||
it('is true for Mastodon 3.0.0+', () => {
|
||||
let instance = fromJS({ version: '3.0.0' });
|
||||
let features = getFeatures(instance);
|
||||
expect(features.trends).toBe(true);
|
||||
});
|
||||
|
||||
it('is false for Mastodon < 3.0.0', () => {
|
||||
let instance = fromJS({ version: '2.4.3' });
|
||||
let features = getFeatures(instance);
|
||||
expect(features.trends).toBe(false);
|
||||
});
|
||||
|
||||
it('is false for Pleroma', () => {
|
||||
let instance = fromJS({
|
||||
version: '2.7.2 (compatible; Pleroma 1.1.50-42-g3d9ac6ae-develop)',
|
||||
});
|
||||
let features = getFeatures(instance);
|
||||
expect(features.trends).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
21
app/gabsocial/utils/features.js
Normal file
21
app/gabsocial/utils/features.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
// Detect backend features to conditionally render elements
|
||||
import semver from 'semver';
|
||||
|
||||
export const getFeatures = instance => {
|
||||
const v = parseVersion(instance.get('version'));
|
||||
return {
|
||||
suggestions: v.software === 'Mastodon' && semver.gte(v.compatVersion, '2.4.3'),
|
||||
trends: v.software === 'Mastodon' && semver.gte(v.compatVersion, '3.0.0'),
|
||||
emojiReacts: v.software === 'Pleroma' && semver.gte(v.version, '2.0.0'),
|
||||
};
|
||||
};
|
||||
|
||||
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],
|
||||
};
|
||||
};
|
10
package.json
10
package.json
|
@ -4,10 +4,13 @@
|
|||
"description": "Soapbox frontend for Pleroma.",
|
||||
"homepage": "https://soapbox.pub/",
|
||||
"repository": {
|
||||
"type" : "git",
|
||||
"url" : "https://gitlab.com/soapbox-pub/soapbox-fe.git"
|
||||
"type": "git",
|
||||
"url": "https://gitlab.com/soapbox-pub/soapbox-fe.git"
|
||||
},
|
||||
"keywords": ["fediverse", "pleroma"],
|
||||
"keywords": [
|
||||
"fediverse",
|
||||
"pleroma"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://gitlab.com/soapbox-pub/soapbox-fe/-/issues"
|
||||
},
|
||||
|
@ -125,6 +128,7 @@
|
|||
"rimraf": "^3.0.0",
|
||||
"sass": "^1.20.3",
|
||||
"sass-loader": "^8.0.0",
|
||||
"semver": "^7.3.2",
|
||||
"stringz": "^2.0.0",
|
||||
"substring-trie": "^1.0.2",
|
||||
"throng": "^4.0.0",
|
||||
|
|
|
@ -9388,6 +9388,11 @@ semver@^6.1.1:
|
|||
resolved "https://registry.yarnpkg.com/semver/-/semver-6.1.1.tgz#53f53da9b30b2103cd4f15eab3a18ecbcb210c9b"
|
||||
integrity sha512-rWYq2e5iYW+fFe/oPPtYJxYgjBm8sC4rmoGdUOgBB7VnwKt6HrL793l2voH1UlsyYZpJ4g0wfjnTEO1s1NP2eQ==
|
||||
|
||||
semver@^7.3.2:
|
||||
version "7.3.2"
|
||||
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.2.tgz#604962b052b81ed0786aae84389ffba70ffd3938"
|
||||
integrity sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==
|
||||
|
||||
send@0.17.1:
|
||||
version "0.17.1"
|
||||
resolved "https://registry.yarnpkg.com/send/-/send-0.17.1.tgz#c1d8b059f7900f7466dd4938bdc44e11ddb376c8"
|
||||
|
|
Loading…
Reference in a new issue