feat: save user preferences (kind 30078) & encrypt it

This commit is contained in:
P. Reis 2024-04-28 17:07:41 -03:00
parent 42bbc09a91
commit 6627704114
1 changed files with 12 additions and 0 deletions

View File

@ -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);
};