From 6e6698a4b520adaa1fc192e3a539033acaf5671b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicole=20Miko=C5=82ajczyk?= Date: Wed, 9 Apr 2025 10:29:32 +0200 Subject: [PATCH] pl-api: support settings store in mitra MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicole Mikołajczyk --- packages/pl-api/lib/client.ts | 20 ++++++- packages/pl-api/lib/features.ts | 72 ++++++++++++-------------- packages/pl-fe/src/actions/settings.ts | 2 +- 3 files changed, 51 insertions(+), 43 deletions(-) diff --git a/packages/pl-api/lib/client.ts b/packages/pl-api/lib/client.ts index 6c37f9cce..bdf198b88 100644 --- a/packages/pl-api/lib/client.ts +++ b/packages/pl-api/lib/client.ts @@ -1171,6 +1171,14 @@ class PlApiClient { if (params.settings_store) { (params as any).pleroma_settings_store = params.settings_store; + + if (this.features.version.software === MITRA) { + await this.request('/api/v1/settings/client_config', { + method: 'POST', + body: params.settings_store, + }); + } + delete params.settings_store; } @@ -3399,9 +3407,17 @@ class PlApiClient { * Requires features{@link Features['frontendConfigurations']}. */ getFrontendConfigurations: async () => { - const response = await this.request('/api/pleroma/frontend_configurations'); + let response; - return v.parse(v.fallback(v.record(v.string(), v.record(v.string(), v.any())), {}), response.json); + switch (this.features.version.software) { + case MITRA: + response = (await this.request('/api/v1/accounts/verify_credentials')).json?.client_config; + break; + default: + response = (await this.request('/api/pleroma/frontend_configurations')).json; + } + + return v.parse(v.fallback(v.record(v.string(), v.record(v.string(), v.any())), {}), response); }, }; diff --git a/packages/pl-api/lib/features.ts b/packages/pl-api/lib/features.ts index ccebf53b3..05bbc5788 100644 --- a/packages/pl-api/lib/features.ts +++ b/packages/pl-api/lib/features.ts @@ -286,6 +286,36 @@ const getFeatures = (instance: Instance) => { v.software === PLEROMA, ]), + /** + * @see GET /api/v1/admin/custom_emojis + * @see GET /api/v1/admin/custom_emojis/:id + * @see POST /api/v1/admin/custom_emojis + * @see PATCH /api/v1/admin/custom_emojis/:id + * @see DELETE /api/v1/admin/custom_emojis/:id + */ + adminCustomEmojis: v.software === GOTOSOCIAL, + + /** + * Ability to manage instance rules by admins. + * @see GET /api/v1/pleroma/admin/rules + * @see POST /api/v1/pleroma/admin/rules + * @see PATCH /api/v1/pleroma/admin/rules/:id + * @see DELETE /api/v1/pleroma/admin/rules/:id + * @see GET /api/v1/admin/instance/rules + * @see GET /api/v1/admin/instance/rules/:id + * @see POST /api/v1/admin/instance/rules + * @see PATCH /api/v1/admin/instance/rules/:id + * @see DELETE /api/v1/admin/instance/rules/:id + */ + adminRules: any([ + v.software === GOTOSOCIAL, + v.software === PLEROMA && gte(v.version, '2.7.0'), + ]), + + adminRulesPriority: any([ + v.software === PLEROMA && gte(v.version, '2.7.0'), + ]), + /** * Can display announcements set by admins. * @see GET /api/v1/announcements @@ -745,44 +775,15 @@ const getFeatures = (instance: Instance) => { /** * Whether client settings can be retrieved from the API. * @see GET /api/pleroma/frontend_configurations + * @see PATCH /api/v1/accounts/update_credentials */ frontendConfigurations: any([ v.software === AKKOMA, v.software === DITTO, - v.software === ICESHRIMP_NET, + v.software === MITRA && gte(v.version, '1.20.0'), v.software === PLEROMA, ]), - /** - * @see GET /api/v1/admin/custom_emojis - * @see GET /api/v1/admin/custom_emojis/:id - * @see POST /api/v1/admin/custom_emojis - * @see PATCH /api/v1/admin/custom_emojis/:id - * @see DELETE /api/v1/admin/custom_emojis/:id - */ - adminCustomEmojis: v.software === GOTOSOCIAL, - - /** - * Ability to manage instance rules by admins. - * @see GET /api/v1/pleroma/admin/rules - * @see POST /api/v1/pleroma/admin/rules - * @see PATCH /api/v1/pleroma/admin/rules/:id - * @see DELETE /api/v1/pleroma/admin/rules/:id - * @see GET /api/v1/admin/instance/rules - * @see GET /api/v1/admin/instance/rules/:id - * @see POST /api/v1/admin/instance/rules - * @see PATCH /api/v1/admin/instance/rules/:id - * @see DELETE /api/v1/admin/instance/rules/:id - */ - adminRules: any([ - v.software === GOTOSOCIAL, - v.software === PLEROMA && gte(v.version, '2.7.0'), - ]), - - adminRulesPriority: any([ - v.software === PLEROMA && gte(v.version, '2.7.0'), - ]), - /** * @see GET /api/v2/notifications/:group_key * @see GET /api/v2/notifications/:group_key @@ -1451,15 +1452,6 @@ const getFeatures = (instance: Instance) => { v.software === GOTOSOCIAL && gte(v.version, '0.18.2'), ]), - /** - * Can store client settings in the database. - * @see PATCH /api/v1/accounts/update_credentials - */ - settingsStore: any([ - v.software === AKKOMA, - v.software === PLEROMA, - ]), - shoutbox: instance.api_versions['shout.pleroma.pl-api'] >= 1, /** diff --git a/packages/pl-fe/src/actions/settings.ts b/packages/pl-fe/src/actions/settings.ts index 9d91fac6a..ac870418f 100644 --- a/packages/pl-fe/src/actions/settings.ts +++ b/packages/pl-fe/src/actions/settings.ts @@ -68,7 +68,7 @@ const updateSettingsStore = (settings: any) => const state = getState(); const client = getClient(state); - if (client.features.settingsStore) { + if (client.features.frontendConfigurations) { return dispatch(patchMe({ settings_store: { [FE_NAME]: settings,