2018-09-18 13:08:27 +09:00
|
|
|
import * as Router from 'koa-router';
|
|
|
|
import config from '../../config';
|
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 renderNote from '../../remote/activitypub/renderer/note';
|
2019-04-07 21:50:36 +09:00
|
|
|
import { Users, Notes, UserNotePinings } from '../../models';
|
2019-04-13 01:43:22 +09:00
|
|
|
import { ensure } from '../../prelude/ensure';
|
2018-09-18 13:08:27 +09:00
|
|
|
|
|
|
|
export default async (ctx: Router.IRouterContext) => {
|
2019-04-07 21:50:36 +09:00
|
|
|
const userId = ctx.params.user;
|
2018-09-18 13:08:27 +09:00
|
|
|
|
|
|
|
// Verify user
|
2019-04-07 21:50:36 +09:00
|
|
|
const user = await Users.findOne({
|
|
|
|
id: userId,
|
2018-09-18 13:08:27 +09:00
|
|
|
host: null
|
|
|
|
});
|
|
|
|
|
2019-04-07 21:50:36 +09:00
|
|
|
if (user == null) {
|
2018-09-18 13:08:27 +09:00
|
|
|
ctx.status = 404;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-12 09:37:00 +09:00
|
|
|
const pinings = await UserNotePinings.find({
|
|
|
|
where: { userId: user.id },
|
|
|
|
order: { id: 'DESC' }
|
|
|
|
});
|
2018-09-18 13:08:27 +09:00
|
|
|
|
2019-04-13 01:43:22 +09:00
|
|
|
const pinnedNotes = await Promise.all(pinings.map(pining =>
|
|
|
|
Notes.findOne(pining.noteId).then(ensure)));
|
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`,
|
2019-04-13 01:43:22 +09:00
|
|
|
renderedNotes.length, undefined, undefined, renderedNotes
|
2018-09-18 13:08:27 +09:00
|
|
|
);
|
|
|
|
|
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);
|
|
|
|
};
|