mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Add blockController, fix bugs
This commit is contained in:
parent
6d1375ba59
commit
84eb4cec2e
5 changed files with 20 additions and 2 deletions
|
|
@ -23,6 +23,7 @@ import {
|
||||||
accountLookupController,
|
accountLookupController,
|
||||||
accountSearchController,
|
accountSearchController,
|
||||||
accountStatusesController,
|
accountStatusesController,
|
||||||
|
blockController,
|
||||||
createAccountController,
|
createAccountController,
|
||||||
favouritesController,
|
favouritesController,
|
||||||
followController,
|
followController,
|
||||||
|
|
@ -135,6 +136,7 @@ app.patch(
|
||||||
app.get('/api/v1/accounts/search', accountSearchController);
|
app.get('/api/v1/accounts/search', accountSearchController);
|
||||||
app.get('/api/v1/accounts/lookup', accountLookupController);
|
app.get('/api/v1/accounts/lookup', accountLookupController);
|
||||||
app.get('/api/v1/accounts/relationships', relationshipsController);
|
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.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}}/followers', followersController);
|
||||||
app.get('/api/v1/accounts/:pubkey{[0-9a-f]{64}}/following', followingController);
|
app.get('/api/v1/accounts/:pubkey{[0-9a-f]{64}}/following', followingController);
|
||||||
|
|
|
||||||
|
|
@ -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. */
|
/** Publish an event to the given relays, or the entire pool. */
|
||||||
function storeEvent(event: Event, opts: StoreEventOpts = {}): Promise<void> {
|
function storeEvent(event: Event, opts: StoreEventOpts = {}): Promise<void> {
|
||||||
const { relays = activeRelays } = opts;
|
const { relays = activeRelays } = opts;
|
||||||
|
const debug = Debug('ditto:client:publish');
|
||||||
debug('EVENT', event);
|
debug('EVENT', event);
|
||||||
pool.publish(event, relays);
|
pool.publish(event, relays);
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
|
|
|
||||||
|
|
@ -246,6 +246,20 @@ const followingController: AppController = async (c) => {
|
||||||
return c.json(accounts.filter(Boolean));
|
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 favouritesController: AppController = async (c) => {
|
||||||
const pubkey = c.get('pubkey')!;
|
const pubkey = c.get('pubkey')!;
|
||||||
const params = paginationSchema.parse(c.req.query());
|
const params = paginationSchema.parse(c.req.query());
|
||||||
|
|
@ -275,6 +289,7 @@ export {
|
||||||
accountLookupController,
|
accountLookupController,
|
||||||
accountSearchController,
|
accountSearchController,
|
||||||
accountStatusesController,
|
accountStatusesController,
|
||||||
|
blockController,
|
||||||
createAccountController,
|
createAccountController,
|
||||||
favouritesController,
|
favouritesController,
|
||||||
followController,
|
followController,
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ function updateListEvent<K extends number>(
|
||||||
): Promise<Event<K>> {
|
): Promise<Event<K>> {
|
||||||
return updateEvent(filter, (prev) => ({
|
return updateEvent(filter, (prev) => ({
|
||||||
kind: filter.kinds[0],
|
kind: filter.kinds[0],
|
||||||
content: prev?.content,
|
content: prev?.content ?? '',
|
||||||
tags: fn(prev?.tags ?? []),
|
tags: fn(prev?.tags ?? []),
|
||||||
}), c);
|
}), c);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ async function renderRelationship(sourcePubkey: string, targetPubkey: string) {
|
||||||
showing_reblogs: true,
|
showing_reblogs: true,
|
||||||
notifying: false,
|
notifying: false,
|
||||||
followed_by: target3 ? hasTag(target3?.tags, ['p', sourcePubkey]) : 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,
|
blocked_by: target10000 ? hasTag(target10000.tags, ['p', sourcePubkey]) : false,
|
||||||
muting: false,
|
muting: false,
|
||||||
muting_notifications: false,
|
muting_notifications: false,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue