Add favourited_by and reblogged_by controllers

This commit is contained in:
Alex Gleason
2023-08-29 18:08:00 -05:00
parent 9b761ff960
commit b27b84e3fb
4 changed files with 56 additions and 5 deletions

View File

@@ -30,6 +30,15 @@ const instanceController: AppController = (c) => {
max_media_attachments: 20,
},
},
pleroma: {
metadata: {
features: [
'mastodon_api',
'mastodon_api_streaming',
'exposable_reactions',
],
},
},
languages: ['en'],
stats: {
domain_count: 0,

View File

@@ -1,8 +1,9 @@
import { type AppController } from '@/app.ts';
import { type Event, ISO6391, z } from '@/deps.ts';
import { getAncestors, getDescendants, getEvent } from '@/queries.ts';
import { toStatus } from '@/transformers/nostr-to-mastoapi.ts';
import { createEvent, parseBody } from '@/utils/web.ts';
import * as mixer from '@/mixer.ts';
import { getAncestors, getAuthor, getDescendants, getEvent } from '@/queries.ts';
import { toAccount, toStatus } from '@/transformers/nostr-to-mastoapi.ts';
import { createEvent, paginated, parseBody } from '@/utils/web.ts';
const createStatusSchema = z.object({
in_reply_to_id: z.string().regex(/[0-9a-f]{64}/).nullish(),
@@ -128,4 +129,41 @@ const favouriteController: AppController = async (c) => {
}
};
export { contextController, createStatusController, favouriteController, statusController };
const favouritedByController: AppController = async (c) => {
const id = c.req.param('id');
const events = await mixer.getFilters([{ kinds: [7], '#e': [id] }]);
const accounts = await Promise.all(events.map(async ({ pubkey }) => {
const author = await getAuthor(pubkey);
if (author) {
return toAccount(author);
}
}));
return paginated(c, events, accounts);
};
const rebloggedByController: AppController = async (c) => {
const id = c.req.param('id');
const events = await mixer.getFilters([{ kinds: [6], '#e': [id] }]);
const accounts = await Promise.all(events.map(async ({ pubkey }) => {
const author = await getAuthor(pubkey);
if (author) {
return toAccount(author);
}
}));
return paginated(c, events, accounts);
};
export {
contextController,
createStatusController,
favouriteController,
favouritedByController,
rebloggedByController,
statusController,
};