diff --git a/src/app.ts b/src/app.ts index c3212f8f..e637cb4f 100644 --- a/src/app.ts +++ b/src/app.ts @@ -23,6 +23,7 @@ import { accountLookupController, accountSearchController, accountStatusesController, + blockController, createAccountController, favouritesController, followController, @@ -135,6 +136,7 @@ app.patch( app.get('/api/v1/accounts/search', accountSearchController); app.get('/api/v1/accounts/lookup', accountLookupController); app.get('/api/v1/accounts/relationships', relationshipsController); +app.post('/api/v1/accounts/:pubkey{[0-9a-f]{64}}/block', blockController); app.post('/api/v1/accounts/:pubkey{[0-9a-f]{64}}/follow', followController); app.get('/api/v1/accounts/:pubkey{[0-9a-f]{64}}/followers', followersController); app.get('/api/v1/accounts/:pubkey{[0-9a-f]{64}}/following', followingController); diff --git a/src/client.ts b/src/client.ts index fbcfaa5f..511cbc75 100644 --- a/src/client.ts +++ b/src/client.ts @@ -52,6 +52,7 @@ function getEvents(filters: Filter[], opts: GetEventsOpts = /** Publish an event to the given relays, or the entire pool. */ function storeEvent(event: Event, opts: StoreEventOpts = {}): Promise { const { relays = activeRelays } = opts; + const debug = Debug('ditto:client:publish'); debug('EVENT', event); pool.publish(event, relays); return Promise.resolve(); diff --git a/src/controllers/api/accounts.ts b/src/controllers/api/accounts.ts index 5609fbef..9e1acc80 100644 --- a/src/controllers/api/accounts.ts +++ b/src/controllers/api/accounts.ts @@ -246,6 +246,20 @@ const followingController: AppController = async (c) => { return c.json(accounts.filter(Boolean)); }; +const blockController: AppController = async (c) => { + const sourcePubkey = c.get('pubkey')!; + const targetPubkey = c.req.param('pubkey'); + + await updateListEvent( + { kinds: [10000], authors: [sourcePubkey] }, + (tags) => addTag(tags, ['p', targetPubkey]), + c, + ); + + const relationship = await renderRelationship(sourcePubkey, targetPubkey); + return c.json(relationship); +}; + const favouritesController: AppController = async (c) => { const pubkey = c.get('pubkey')!; const params = paginationSchema.parse(c.req.query()); @@ -275,6 +289,7 @@ export { accountLookupController, accountSearchController, accountStatusesController, + blockController, createAccountController, favouritesController, followController, diff --git a/src/utils/web.ts b/src/utils/web.ts index 3687a652..1e7be076 100644 --- a/src/utils/web.ts +++ b/src/utils/web.ts @@ -60,7 +60,7 @@ function updateListEvent( ): Promise> { return updateEvent(filter, (prev) => ({ kind: filter.kinds[0], - content: prev?.content, + content: prev?.content ?? '', tags: fn(prev?.tags ?? []), }), c); } diff --git a/src/views/mastodon/relationships.ts b/src/views/mastodon/relationships.ts index 97fa0f13..e5ce2807 100644 --- a/src/views/mastodon/relationships.ts +++ b/src/views/mastodon/relationships.ts @@ -15,7 +15,7 @@ async function renderRelationship(sourcePubkey: string, targetPubkey: string) { showing_reblogs: true, notifying: false, followed_by: target3 ? hasTag(target3?.tags, ['p', sourcePubkey]) : false, - blocking: event10000 ? hasTag(target10000.tags, ['p', targetPubkey]) : false, + blocking: event10000 ? hasTag(event10000.tags, ['p', targetPubkey]) : false, blocked_by: target10000 ? hasTag(target10000.tags, ['p', sourcePubkey]) : false, muting: false, muting_notifications: false,