Revert "fix(updateCredentialsController): stop overwriting kind 0 unnecessarily"

This reverts commit 342ba7d4b1.
This commit is contained in:
P. Reis 2024-12-03 14:23:00 -03:00
parent 342ba7d4b1
commit b45fcdde69

View file

@ -1,4 +1,4 @@
import { NostrEvent, NostrFilter, NSchema as n } from '@nostrify/nostrify'; import { 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,28 +288,12 @@ 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 kind0fields = { const event = await updateEvent(
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);
@ -323,7 +307,7 @@ const updateCredentialsController: AppController = async (c) => {
lud16, lud16,
website, website,
bot, bot,
} = kind0fields; } = result.data;
const [avatar, header] = await Promise.all([ const [avatar, header] = await Promise.all([
avatarFile ? uploadFile(c, avatarFile, { pubkey }) : undefined, avatarFile ? uploadFile(c, avatarFile, { pubkey }) : undefined,
@ -357,9 +341,6 @@ 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 });