diff --git a/app/soapbox/__fixtures__/mastodon-instance-rc.json b/app/soapbox/__fixtures__/mastodon-instance-rc.json
new file mode 100644
index 000000000..277839d14
--- /dev/null
+++ b/app/soapbox/__fixtures__/mastodon-instance-rc.json
@@ -0,0 +1,123 @@
+{
+ "uri": "mastodon.social",
+ "title": "Mastodon",
+ "short_description": "Server run by the main developers of the project It is not focused on any particular niche interest - everyone is welcome as long as you follow our code of conduct!",
+ "description": "Server run by the main developers of the project
It is not focused on any particular niche interest - everyone is welcome as long as you follow our code of conduct!",
+ "email": "staff@mastodon.social",
+ "version": "3.5.0rc1",
+ "urls": {
+ "streaming_api": "wss://mastodon.social"
+ },
+ "stats": {
+ "user_count": 635078,
+ "status_count": 34700866,
+ "domain_count": 21989
+ },
+ "thumbnail": "https://files.mastodon.social/site_uploads/files/000/000/001/original/vlcsnap-2018-08-27-16h43m11s127.png",
+ "languages": [
+ "en"
+ ],
+ "registrations": true,
+ "approval_required": false,
+ "invites_enabled": true,
+ "configuration": {
+ "statuses": {
+ "max_characters": 500,
+ "max_media_attachments": 4,
+ "characters_reserved_per_url": 23
+ },
+ "media_attachments": {
+ "supported_mime_types": [
+ "image/jpeg",
+ "image/png",
+ "image/gif",
+ "video/webm",
+ "video/mp4",
+ "video/quicktime",
+ "video/ogg",
+ "audio/wave",
+ "audio/wav",
+ "audio/x-wav",
+ "audio/x-pn-wave",
+ "audio/ogg",
+ "audio/vorbis",
+ "audio/mpeg",
+ "audio/mp3",
+ "audio/webm",
+ "audio/flac",
+ "audio/aac",
+ "audio/m4a",
+ "audio/x-m4a",
+ "audio/mp4",
+ "audio/3gpp",
+ "video/x-ms-asf"
+ ],
+ "image_size_limit": 10485760,
+ "image_matrix_limit": 16777216,
+ "video_size_limit": 41943040,
+ "video_frame_rate_limit": 60,
+ "video_matrix_limit": 2304000
+ },
+ "polls": {
+ "max_options": 4,
+ "max_characters_per_option": 50,
+ "min_expiration": 300,
+ "max_expiration": 2629746
+ }
+ },
+ "contact_account": {
+ "id": "1",
+ "username": "Gargron",
+ "acct": "Gargron",
+ "display_name": "Eugen",
+ "locked": false,
+ "bot": false,
+ "discoverable": true,
+ "group": false,
+ "created_at": "2016-03-16T00:00:00.000Z",
+ "note": "
Founder, CEO and lead developer @Mastodon, Germany.
", + "url": "https://mastodon.social/@Gargron", + "avatar": "https://files.mastodon.social/accounts/avatars/000/000/001/original/ccb05a778962e171.png", + "avatar_static": "https://files.mastodon.social/accounts/avatars/000/000/001/original/ccb05a778962e171.png", + "header": "https://files.mastodon.social/accounts/headers/000/000/001/original/3b91c9965d00888b.jpeg", + "header_static": "https://files.mastodon.social/accounts/headers/000/000/001/original/3b91c9965d00888b.jpeg", + "followers_count": 99760, + "following_count": 274, + "statuses_count": 71657, + "last_status_at": "2022-03-17", + "emojis": [], + "fields": [ + { + "name": "Patreon", + "value": "https://www.patreon.com/mastodon", + "verified_at": null + } + ] + }, + "rules": [ + { + "id": "1", + "text": "Sexually explicit or violent media must be marked as sensitive when posting" + }, + { + "id": "2", + "text": "No racism, sexism, homophobia, transphobia, xenophobia, or casteism" + }, + { + "id": "3", + "text": "No incitement of violence or promotion of violent ideologies" + }, + { + "id": "4", + "text": "No harassment, dogpiling or doxxing of other users" + }, + { + "id": "5", + "text": "No content illegal in Germany" + }, + { + "id": "7", + "text": "Do not share intentionally false or misleading information" + } + ] +} diff --git a/app/soapbox/actions/external_auth.js b/app/soapbox/actions/external_auth.js index f4058cba2..8bf0bba3f 100644 --- a/app/soapbox/actions/external_auth.js +++ b/app/soapbox/actions/external_auth.js @@ -6,11 +6,10 @@ * @see module:soapbox/actions/oauth */ -import { Map as ImmutableMap, fromJS } from 'immutable'; - import { createApp } from 'soapbox/actions/apps'; import { authLoggedIn, verifyCredentials, switchAccount } from 'soapbox/actions/auth'; import { obtainOAuthToken } from 'soapbox/actions/oauth'; +import { normalizeInstance } from 'soapbox/normalizers'; import { parseBaseURL } from 'soapbox/utils/auth'; import sourceCode from 'soapbox/utils/code'; import { getWalletAndSign } from 'soapbox/utils/ethereum'; @@ -22,12 +21,12 @@ import { baseClient } from '../api'; const fetchExternalInstance = baseURL => { return baseClient(null, baseURL) .get('/api/v1/instance') - .then(({ data: instance }) => fromJS(instance)) + .then(({ data: instance }) => normalizeInstance(instance)) .catch(error => { if (error.response?.status === 401) { // Authenticated fetch is enabled. // Continue with a limited featureset. - return ImmutableMap({ version: '0.0.0' }); + return normalizeInstance({}); } else { throw error; } diff --git a/app/soapbox/normalizers/__tests__/instance-test.js b/app/soapbox/normalizers/__tests__/instance-test.js index 2df36734f..f5fd4f6af 100644 --- a/app/soapbox/normalizers/__tests__/instance-test.js +++ b/app/soapbox/normalizers/__tests__/instance-test.js @@ -177,4 +177,11 @@ describe('normalizeInstance()', () => { expect(result.get('configuration') instanceof ImmutableMap).toBe(true); expect(result.get('description_limit')).toBe(1500); }); + + it('normalizes a Mastodon RC version', () => { + const instance = require('soapbox/__fixtures__/mastodon-instance-rc.json'); + const result = normalizeInstance(instance); + + expect(result.version).toEqual('3.5.0-rc1'); + }); }); diff --git a/app/soapbox/normalizers/instance.ts b/app/soapbox/normalizers/instance.ts index 6e2c0b4f9..a33601bf9 100644 --- a/app/soapbox/normalizers/instance.ts +++ b/app/soapbox/normalizers/instance.ts @@ -84,6 +84,18 @@ const pleromaToMastodonConfig = (instance: ImmutableMap