2018-12-16 01:44:59 +09:00
|
|
|
import { ObjectID } from 'mongodb';
|
2018-09-18 13:08:27 +09:00
|
|
|
import * as Router from 'koa-router';
|
|
|
|
import config from '../../config';
|
|
|
|
import User from '../../models/user';
|
2019-01-31 02:29:36 +09:00
|
|
|
import { renderActivity } from '../../remote/activitypub/renderer';
|
2018-09-18 13:08:27 +09:00
|
|
|
import renderOrderedCollection from '../../remote/activitypub/renderer/ordered-collection';
|
|
|
|
import { setResponseType } from '../activitypub';
|
|
|
|
import Note from '../../models/note';
|
|
|
|
import renderNote from '../../remote/activitypub/renderer/note';
|
|
|
|
|
|
|
|
export default async (ctx: Router.IRouterContext) => {
|
2018-12-16 01:44:59 +09:00
|
|
|
if (!ObjectID.isValid(ctx.params.user)) {
|
|
|
|
ctx.status = 404;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const userId = new ObjectID(ctx.params.user);
|
2018-09-18 13:08:27 +09:00
|
|
|
|
|
|
|
// Verify user
|
|
|
|
const user = await User.findOne({
|
|
|
|
_id: userId,
|
|
|
|
host: null
|
|
|
|
});
|
|
|
|
|
|
|
|
if (user === null) {
|
|
|
|
ctx.status = 404;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const pinnedNoteIds = user.pinnedNoteIds || [];
|
|
|
|
|
2018-12-16 01:44:59 +09:00
|
|
|
const pinnedNotes = await Promise.all(pinnedNoteIds.filter(ObjectID.isValid).map(id => Note.findOne({ _id: id })));
|
2018-09-18 13:08:27 +09:00
|
|
|
|
|
|
|
const renderedNotes = await Promise.all(pinnedNotes.map(note => renderNote(note)));
|
|
|
|
|
|
|
|
const rendered = renderOrderedCollection(
|
|
|
|
`${config.url}/users/${userId}/collections/featured`,
|
|
|
|
renderedNotes.length, null, null, renderedNotes
|
|
|
|
);
|
|
|
|
|
2019-01-31 02:29:36 +09:00
|
|
|
ctx.body = renderActivity(rendered);
|
2018-09-19 07:17:19 +09:00
|
|
|
ctx.set('Cache-Control', 'private, max-age=0, must-revalidate');
|
2018-09-18 13:08:27 +09:00
|
|
|
setResponseType(ctx);
|
|
|
|
};
|