Add bookmarkController

This commit is contained in:
Alex Gleason 2024-01-01 13:45:07 -06:00
parent 89bdc21caa
commit 69a44f9d2b
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 33 additions and 2 deletions

View File

@ -47,6 +47,7 @@ import { preferencesController } from './controllers/api/preferences.ts';
import { relayController } from './controllers/nostr/relay.ts';
import { searchController } from './controllers/api/search.ts';
import {
bookmarkController,
contextController,
createStatusController,
favouriteController,
@ -152,7 +153,8 @@ app.get('/api/v1/statuses/:id{[0-9a-f]{64}}/favourited_by', favouritedByControll
app.get('/api/v1/statuses/:id{[0-9a-f]{64}}/reblogged_by', rebloggedByController);
app.get('/api/v1/statuses/:id{[0-9a-f]{64}}/context', contextController);
app.get('/api/v1/statuses/:id{[0-9a-f]{64}}', statusController);
app.post('/api/v1/statuses/:id{[0-9a-f]{64}}/favourite', favouriteController);
app.post('/api/v1/statuses/:id{[0-9a-f]{64}}/favourite', requirePubkey, favouriteController);
app.post('/api/v1/statuses/:id{[0-9a-f]{64}}/bookmark', requirePubkey, bookmarkController);
app.post('/api/v1/statuses', requirePubkey, createStatusController);
app.post('/api/v1/media', requireRole('user', { validatePayload: false }), mediaController);

View File

@ -2,7 +2,8 @@ import { type AppController } from '@/app.ts';
import { getUnattachedMediaByIds } from '@/db/unattached-media.ts';
import { type Event, ISO6391, z } from '@/deps.ts';
import { getAncestors, getAuthor, getDescendants, getEvent } from '@/queries.ts';
import { createEvent, paginationSchema, parseBody } from '@/utils/web.ts';
import { addTag } from '@/tags.ts';
import { createEvent, paginationSchema, parseBody, updateListEvent } from '@/utils/web.ts';
import { renderEventAccounts } from '@/views.ts';
import { renderStatus } from '@/views/mastodon/statuses.ts';
@ -152,7 +153,35 @@ const rebloggedByController: AppController = (c) => {
return renderEventAccounts(c, [{ kinds: [6], '#e': [id], ...params }]);
};
/** https://docs.joinmastodon.org/methods/statuses/#bookmark */
const bookmarkController: AppController = async (c) => {
const pubkey = c.get('pubkey')!;
const eventId = c.req.param('id');
const event = await getEvent(eventId, {
kind: 1,
relations: ['author', 'event_stats', 'author_stats'],
});
if (event) {
await updateListEvent(
{ kinds: [10003], authors: [pubkey] },
(tags) => addTag(tags, ['e', eventId]),
c,
);
const status = await renderStatus(event, pubkey);
if (status) {
status.bookmarked = true;
}
return c.json(status);
} else {
return c.json({ error: 'Event not found.' }, 404);
}
};
export {
bookmarkController,
contextController,
createStatusController,
favouriteController,