Add blockController, fix bugs

This commit is contained in:
Alex Gleason 2023-12-31 23:35:37 -06:00
parent 6d1375ba59
commit 84eb4cec2e
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
5 changed files with 20 additions and 2 deletions

View File

@ -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);

View File

@ -52,6 +52,7 @@ function getEvents<K extends number>(filters: Filter<K>[], opts: GetEventsOpts =
/** Publish an event to the given relays, or the entire pool. */
function storeEvent(event: Event, opts: StoreEventOpts = {}): Promise<void> {
const { relays = activeRelays } = opts;
const debug = Debug('ditto:client:publish');
debug('EVENT', event);
pool.publish(event, relays);
return Promise.resolve();

View File

@ -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,

View File

@ -60,7 +60,7 @@ function updateListEvent<K extends number>(
): Promise<Event<K>> {
return updateEvent(filter, (prev) => ({
kind: filter.kinds[0],
content: prev?.content,
content: prev?.content ?? '',
tags: fn(prev?.tags ?? []),
}), c);
}

View File

@ -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,