From 5f6715db468a952480bea212cdc5ed97d7ce7dfd Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 1 Jan 2024 14:35:46 -0600 Subject: [PATCH] Add unbookmarkController --- src/app.ts | 2 ++ src/controllers/api/statuses.ts | 30 +++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/app.ts b/src/app.ts index b5464ee..cbfe5b1 100644 --- a/src/app.ts +++ b/src/app.ts @@ -55,6 +55,7 @@ import { favouritedByController, rebloggedByController, statusController, + unbookmarkController, } from './controllers/api/statuses.ts'; import { streamingController } from './controllers/api/streaming.ts'; import { @@ -156,6 +157,7 @@ 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', requirePubkey, favouriteController); app.post('/api/v1/statuses/:id{[0-9a-f]{64}}/bookmark', requirePubkey, bookmarkController); +app.post('/api/v1/statuses/:id{[0-9a-f]{64}}/unbookmark', requirePubkey, unbookmarkController); app.post('/api/v1/statuses', requirePubkey, createStatusController); app.post('/api/v1/media', requireRole('user', { validatePayload: false }), mediaController); diff --git a/src/controllers/api/statuses.ts b/src/controllers/api/statuses.ts index 241d922..1ba82b3 100644 --- a/src/controllers/api/statuses.ts +++ b/src/controllers/api/statuses.ts @@ -2,7 +2,7 @@ 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 { addTag } from '@/tags.ts'; +import { addTag, deleteTag } from '@/tags.ts'; import { createEvent, paginationSchema, parseBody, updateListEvent } from '@/utils/web.ts'; import { renderEventAccounts } from '@/views.ts'; import { renderStatus } from '@/views/mastodon/statuses.ts'; @@ -180,6 +180,33 @@ const bookmarkController: AppController = async (c) => { } }; +/** https://docs.joinmastodon.org/methods/statuses/#unbookmark */ +const unbookmarkController: 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) => deleteTag(tags, ['e', eventId]), + c, + ); + + const status = await renderStatus(event, pubkey); + if (status) { + status.bookmarked = false; + } + return c.json(status); + } else { + return c.json({ error: 'Event not found.' }, 404); + } +}; + export { bookmarkController, contextController, @@ -188,4 +215,5 @@ export { favouritedByController, rebloggedByController, statusController, + unbookmarkController, };