From eb4aebedd73f176fc368bd50bab67055bd701f2c Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 19 Aug 2023 13:57:17 -0500 Subject: [PATCH] Sync the user on verify_credentials Fixes https://gitlab.com/soapbox-pub/ditto/-/issues/11 --- src/controllers/api/accounts.ts | 4 +++- src/queries.ts | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/controllers/api/accounts.ts b/src/controllers/api/accounts.ts index 84b3ce2..7021b60 100644 --- a/src/controllers/api/accounts.ts +++ b/src/controllers/api/accounts.ts @@ -2,7 +2,7 @@ import { type AppController } from '@/app.ts'; import { type Filter, findReplyTag, z } from '@/deps.ts'; import * as mixer from '@/mixer.ts'; import * as pipeline from '@/pipeline.ts'; -import { getAuthor, getFollows } from '@/queries.ts'; +import { getAuthor, getFollows, syncUser } from '@/queries.ts'; import { booleanParamSchema } from '@/schema.ts'; import { jsonMetaContentSchema } from '@/schemas/nostr.ts'; import { signEvent } from '@/sign.ts'; @@ -25,6 +25,8 @@ const createAccountController: AppController = (c) => { const verifyCredentialsController: AppController = async (c) => { const pubkey = c.get('pubkey')!; + await syncUser(pubkey); + const event = await getAuthor(pubkey); if (event) { return c.json(await toAccount(event, { withSource: true })); diff --git a/src/queries.ts b/src/queries.ts index dc3f7f5..345155b 100644 --- a/src/queries.ts +++ b/src/queries.ts @@ -1,3 +1,4 @@ +import * as client from '@/client.ts'; import * as eventsDB from '@/db/events.ts'; import { type Event, type Filter, findReplyTag } from '@/deps.ts'; import * as mixer from '@/mixer.ts'; @@ -89,4 +90,21 @@ async function isLocallyFollowed(pubkey: string): Promise { return Boolean(event); } -export { getAncestors, getAuthor, getDescendants, getEvent, getFeed, getFollows, getPublicFeed, isLocallyFollowed }; +/** Sync the user's state from other relays. */ +async function syncUser(pubkey: string): Promise { + await client.getFilters([ + { authors: [pubkey], kinds: [0, 3, 10000, 10001, 10002] }, + ], { timeout: 5000 }); +} + +export { + getAncestors, + getAuthor, + getDescendants, + getEvent, + getFeed, + getFollows, + getPublicFeed, + isLocallyFollowed, + syncUser, +};