Merge branch 'favourited-by' into 'develop'

Add favourited_by and reblogged_by controllers

See merge request soapbox-pub/ditto!28
This commit is contained in:
Alex Gleason 2023-08-29 23:09:47 +00:00
commit 62ea00dc6a
4 changed files with 56 additions and 5 deletions

View File

@ -35,6 +35,8 @@ import {
contextController, contextController,
createStatusController, createStatusController,
favouriteController, favouriteController,
favouritedByController,
rebloggedByController,
statusController, statusController,
} from './controllers/api/statuses.ts'; } from './controllers/api/statuses.ts';
import { streamingController } from './controllers/api/streaming.ts'; import { streamingController } from './controllers/api/streaming.ts';
@ -106,6 +108,8 @@ app.post('/api/v1/accounts/:pubkey{[0-9a-f]{64}}/follow', followController);
app.get('/api/v1/accounts/:pubkey{[0-9a-f]{64}}/statuses', accountStatusesController); app.get('/api/v1/accounts/:pubkey{[0-9a-f]{64}}/statuses', accountStatusesController);
app.get('/api/v1/accounts/:pubkey{[0-9a-f]{64}}', accountController); app.get('/api/v1/accounts/:pubkey{[0-9a-f]{64}}', accountController);
app.get('/api/v1/statuses/:id{[0-9a-f]{64}}/favourited_by', favouritedByController);
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}}/context', contextController);
app.get('/api/v1/statuses/:id{[0-9a-f]{64}}', statusController); 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', favouriteController);

View File

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

View File

@ -1,8 +1,9 @@
import { type AppController } from '@/app.ts'; import { type AppController } from '@/app.ts';
import { type Event, ISO6391, z } from '@/deps.ts'; import { type Event, ISO6391, z } from '@/deps.ts';
import { getAncestors, getDescendants, getEvent } from '@/queries.ts'; import * as mixer from '@/mixer.ts';
import { toStatus } from '@/transformers/nostr-to-mastoapi.ts'; import { getAncestors, getAuthor, getDescendants, getEvent } from '@/queries.ts';
import { createEvent, parseBody } from '@/utils/web.ts'; import { toAccount, toStatus } from '@/transformers/nostr-to-mastoapi.ts';
import { createEvent, paginated, parseBody } from '@/utils/web.ts';
const createStatusSchema = z.object({ const createStatusSchema = z.object({
in_reply_to_id: z.string().regex(/[0-9a-f]{64}/).nullish(), 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,
};

View File

@ -75,7 +75,7 @@ type PaginationParams = z.infer<typeof paginationSchema>;
/** Build HTTP Link header for Mastodon API pagination. */ /** Build HTTP Link header for Mastodon API pagination. */
function buildLinkHeader(url: string, events: Event[]): string | undefined { function buildLinkHeader(url: string, events: Event[]): string | undefined {
if (!events.length) return; if (events.length <= 1) return;
const firstEvent = events[0]; const firstEvent = events[0];
const lastEvent = events[events.length - 1]; const lastEvent = events[events.length - 1];