From 66277041143630c382fcf5d9ab585151c0c1ec58 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Sun, 28 Apr 2024 17:07:41 -0300 Subject: [PATCH] feat: save user preferences (kind 30078) & encrypt it --- src/controllers/api/accounts.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/controllers/api/accounts.ts b/src/controllers/api/accounts.ts index 0289799..f6440fe 100644 --- a/src/controllers/api/accounts.ts +++ b/src/controllers/api/accounts.ts @@ -18,6 +18,7 @@ import { accountFromPubkey, renderAccount } from '@/views/mastodon/accounts.ts'; import { renderRelationship } from '@/views/mastodon/relationships.ts'; import { renderStatus } from '@/views/mastodon/statuses.ts'; import { hydrateEvents } from '@/storages/hydrate.ts'; +import { APISigner } from '@/signers/APISigner.ts'; const usernameSchema = z .string().min(1).max(30) @@ -186,6 +187,7 @@ const updateCredentialsSchema = z.object({ bot: z.boolean().optional(), discoverable: z.boolean().optional(), nip05: z.string().optional(), + pleroma_settings_store: z.object({ soapbox_fe: z.object({ themeMode: z.string() }).passthrough() }).optional(), }); const updateCredentialsController: AppController = async (c) => { @@ -225,6 +227,16 @@ const updateCredentialsController: AppController = async (c) => { tags: [], }, c); + const soapbox_fe = result.data.pleroma_settings_store?.soapbox_fe; + if (soapbox_fe) { + const signer = new APISigner(c); + await createEvent({ + kind: 30078, + tags: [['d', 'pub.ditto.preferences']], + content: await signer.nip44.encrypt(pubkey, JSON.stringify(soapbox_fe)), + }, c); + } + const account = await renderAccount(event, { withSource: true }); return c.json(account); };