mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Merge branch 'fix-stop-overwite-kind-0-unnecessarily' into 'main'
fix(updateCredentialsController): stop overwriting kind 0 unnecessarily Closes #269 See merge request soapbox-pub/ditto!598
This commit is contained in:
commit
70d3088735
1 changed files with 60 additions and 45 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';
|
||||||
|
|
||||||
|
|
@ -20,6 +20,7 @@ import { hydrateEvents } from '@/storages/hydrate.ts';
|
||||||
import { bech32ToPubkey } from '@/utils.ts';
|
import { bech32ToPubkey } from '@/utils.ts';
|
||||||
import { addTag, deleteTag, findReplyTag, getTagSet } from '@/utils/tags.ts';
|
import { addTag, deleteTag, findReplyTag, getTagSet } from '@/utils/tags.ts';
|
||||||
import { getPubkeysBySearch } from '@/utils/search.ts';
|
import { getPubkeysBySearch } from '@/utils/search.ts';
|
||||||
|
import { MastodonAccount } from '@/entities/MastodonAccount.ts';
|
||||||
|
|
||||||
const usernameSchema = z
|
const usernameSchema = z
|
||||||
.string().min(1).max(30)
|
.string().min(1).max(30)
|
||||||
|
|
@ -288,12 +289,19 @@ 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 keys = Object.keys(result.data);
|
||||||
|
let event: NostrEvent | undefined;
|
||||||
|
|
||||||
|
if (keys.length === 1 && keys[0] === 'pleroma_settings_store') {
|
||||||
|
event = (await store.query([{ kinds: [0], authors: [pubkey] }]))[0];
|
||||||
|
} else {
|
||||||
|
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);
|
||||||
|
|
@ -341,9 +349,16 @@ const updateCredentialsController: AppController = async (c) => {
|
||||||
},
|
},
|
||||||
c,
|
c,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const settingsStore = result.data.pleroma_settings_store;
|
const settingsStore = result.data.pleroma_settings_store;
|
||||||
const account = await renderAccount(event, { withSource: true, settingsStore });
|
|
||||||
|
let account: MastodonAccount;
|
||||||
|
if (event) {
|
||||||
|
account = await renderAccount(event, { withSource: true, settingsStore });
|
||||||
|
} else {
|
||||||
|
account = await accountFromPubkey(pubkey, { withSource: true, settingsStore });
|
||||||
|
}
|
||||||
|
|
||||||
if (settingsStore) {
|
if (settingsStore) {
|
||||||
await createEvent({
|
await createEvent({
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue