mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
fix(updateCredentialsController): stop overwriting kind 0 unnecessarily
This commit is contained in:
parent
45cb9757b4
commit
342ba7d4b1
1 changed files with 63 additions and 44 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { NostrFilter, NSchema as n } from '@nostrify/nostrify';
|
import { NostrEvent, NostrFilter, NSchema as n } from '@nostrify/nostrify';
|
||||||
import { nip19 } from 'nostr-tools';
|
import { nip19 } from 'nostr-tools';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
|
@ -288,12 +288,28 @@ const updateCredentialsController: AppController = async (c) => {
|
||||||
const pubkey = await signer.getPublicKey();
|
const pubkey = await signer.getPublicKey();
|
||||||
const body = await parseBody(c.req.raw);
|
const body = await parseBody(c.req.raw);
|
||||||
const result = updateCredentialsSchema.safeParse(body);
|
const result = updateCredentialsSchema.safeParse(body);
|
||||||
|
const store = await Storages.db();
|
||||||
|
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
return c.json(result.error, 422);
|
return c.json(result.error, 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
const event = await updateEvent(
|
const kind0fields = {
|
||||||
|
avatar: result.data.avatar,
|
||||||
|
header: result.data.header,
|
||||||
|
display_name: result.data.display_name,
|
||||||
|
fields_attributes: result.data.fields_attributes,
|
||||||
|
note: result.data.note,
|
||||||
|
nip05: result.data.nip05,
|
||||||
|
lud16: result.data.lud16,
|
||||||
|
website: result.data.website,
|
||||||
|
bot: result.data.bot,
|
||||||
|
};
|
||||||
|
const values = Object.values(kind0fields).filter((value) => value !== undefined);
|
||||||
|
let event: NostrEvent;
|
||||||
|
|
||||||
|
if (values.length) {
|
||||||
|
event = await updateEvent(
|
||||||
{ kinds: [0], authors: [pubkey], limit: 1 },
|
{ kinds: [0], authors: [pubkey], limit: 1 },
|
||||||
async (prev) => {
|
async (prev) => {
|
||||||
const meta = n.json().pipe(metadataSchema).catch({}).parse(prev.content);
|
const meta = n.json().pipe(metadataSchema).catch({}).parse(prev.content);
|
||||||
|
|
@ -307,7 +323,7 @@ const updateCredentialsController: AppController = async (c) => {
|
||||||
lud16,
|
lud16,
|
||||||
website,
|
website,
|
||||||
bot,
|
bot,
|
||||||
} = result.data;
|
} = kind0fields;
|
||||||
|
|
||||||
const [avatar, header] = await Promise.all([
|
const [avatar, header] = await Promise.all([
|
||||||
avatarFile ? uploadFile(c, avatarFile, { pubkey }) : undefined,
|
avatarFile ? uploadFile(c, avatarFile, { pubkey }) : undefined,
|
||||||
|
|
@ -341,6 +357,9 @@ const updateCredentialsController: AppController = async (c) => {
|
||||||
},
|
},
|
||||||
c,
|
c,
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
[event] = await store.query([{ kinds: [0], authors: [pubkey] }]);
|
||||||
|
}
|
||||||
|
|
||||||
const settingsStore = result.data.pleroma_settings_store;
|
const settingsStore = result.data.pleroma_settings_store;
|
||||||
const account = await renderAccount(event, { withSource: true, settingsStore });
|
const account = await renderAccount(event, { withSource: true, settingsStore });
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue