refactor: user preference in create & verify credentials
This commit is contained in:
parent
6627704114
commit
bb82df14c6
|
@ -50,7 +50,21 @@ const verifyCredentialsController: AppController = async (c) => {
|
||||||
|
|
||||||
const event = await getAuthor(pubkey, { relations: ['author_stats'] });
|
const event = await getAuthor(pubkey, { relations: ['author_stats'] });
|
||||||
if (event) {
|
if (event) {
|
||||||
return c.json(await renderAccount(event, { withSource: true }));
|
const account = await renderAccount(event, { withSource: true });
|
||||||
|
|
||||||
|
const [userPreferencesEvent] = await eventsDB.query([{
|
||||||
|
authors: [pubkey],
|
||||||
|
kinds: [30078],
|
||||||
|
'#d': ['pub.ditto.pleroma_settings_store'],
|
||||||
|
limit: 1,
|
||||||
|
}]);
|
||||||
|
if (userPreferencesEvent) {
|
||||||
|
const signer = new APISigner(c);
|
||||||
|
const userPreference = JSON.parse(await signer.nip44.decrypt(pubkey, userPreferencesEvent.content));
|
||||||
|
(account.pleroma as any).settings_store = userPreference;
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.json(account);
|
||||||
} else {
|
} else {
|
||||||
return c.json(await accountFromPubkey(pubkey, { withSource: true }));
|
return c.json(await accountFromPubkey(pubkey, { withSource: true }));
|
||||||
}
|
}
|
||||||
|
@ -187,7 +201,7 @@ const updateCredentialsSchema = z.object({
|
||||||
bot: z.boolean().optional(),
|
bot: z.boolean().optional(),
|
||||||
discoverable: z.boolean().optional(),
|
discoverable: z.boolean().optional(),
|
||||||
nip05: z.string().optional(),
|
nip05: z.string().optional(),
|
||||||
pleroma_settings_store: z.object({ soapbox_fe: z.object({ themeMode: z.string() }).passthrough() }).optional(),
|
pleroma_settings_store: z.object({ soapbox_fe: z.record(z.string(), z.unknown()) }).optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateCredentialsController: AppController = async (c) => {
|
const updateCredentialsController: AppController = async (c) => {
|
||||||
|
@ -227,17 +241,30 @@ const updateCredentialsController: AppController = async (c) => {
|
||||||
tags: [],
|
tags: [],
|
||||||
}, c);
|
}, c);
|
||||||
|
|
||||||
const soapbox_fe = result.data.pleroma_settings_store?.soapbox_fe;
|
const pleroma_frontend = result.data.pleroma_settings_store;
|
||||||
if (soapbox_fe) {
|
if (pleroma_frontend) {
|
||||||
const signer = new APISigner(c);
|
const signer = new APISigner(c);
|
||||||
await createEvent({
|
await createEvent({
|
||||||
kind: 30078,
|
kind: 30078,
|
||||||
tags: [['d', 'pub.ditto.preferences']],
|
tags: [['d', 'pub.ditto.pleroma_settings_store']],
|
||||||
content: await signer.nip44.encrypt(pubkey, JSON.stringify(soapbox_fe)),
|
content: await signer.nip44.encrypt(pubkey, JSON.stringify(pleroma_frontend)),
|
||||||
}, c);
|
}, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
const account = await renderAccount(event, { withSource: true });
|
const account = await renderAccount(event, { withSource: true });
|
||||||
|
|
||||||
|
const [userPreferencesEvent] = await eventsDB.query([{
|
||||||
|
authors: [pubkey],
|
||||||
|
kinds: [30078],
|
||||||
|
'#d': ['pub.ditto.pleroma_settings_store'],
|
||||||
|
limit: 1,
|
||||||
|
}]);
|
||||||
|
if (userPreferencesEvent) {
|
||||||
|
const signer = new APISigner(c);
|
||||||
|
const userPreference = JSON.parse(await signer.nip44.decrypt(pubkey, userPreferencesEvent.content));
|
||||||
|
(account.pleroma as any).settings_store = userPreference;
|
||||||
|
}
|
||||||
|
|
||||||
return c.json(account);
|
return c.json(account);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue