feat: repost functionality

This commit is contained in:
P. Reis
2024-04-05 19:44:12 -03:00
parent d688e64219
commit 178a3c4d0e
4 changed files with 51 additions and 6 deletions

View File

@@ -7,7 +7,7 @@ import { jsonMetaContentSchema } from '@/schemas/nostr.ts';
import { addTag, deleteTag } from '@/tags.ts';
import { createEvent, paginationSchema, parseBody, updateListEvent } from '@/utils/api.ts';
import { renderEventAccounts } from '@/views.ts';
import { renderStatus } from '@/views/mastodon/statuses.ts';
import { renderReblog, renderStatus } from '@/views/mastodon/statuses.ts';
import { getLnurl } from '@/utils/lnurl.ts';
const createStatusSchema = z.object({
@@ -173,6 +173,31 @@ const favouritedByController: AppController = (c) => {
return renderEventAccounts(c, [{ kinds: [7], '#e': [id], ...params }]);
};
/** https://docs.joinmastodon.org/methods/statuses/#boost */
const reblogStatusController: AppController = async (c) => {
const eventId = c.req.param('id');
const event = await getEvent(eventId, {
kind: 1,
});
if (event == undefined) {
return c.json({ error: 'Event not found.' }, 404);
}
const tags: string[][] = [['e', event.id], ['p', event.pubkey]];
const reblogEvent = await createEvent({
kind: 6,
content: JSON.stringify(event),
tags,
}, c);
const status = await renderReblog(reblogEvent, reblogEvent.pubkey);
return c.json(status);
};
const rebloggedByController: AppController = (c) => {
const id = c.req.param('id');
const params = paginationSchema.parse(c.req.query());
@@ -339,6 +364,7 @@ export {
favouriteController,
favouritedByController,
pinController,
reblogStatusController,
rebloggedByController,
statusController,
unbookmarkController,