2018-04-01 12:18:36 +02:00
|
|
|
import * as express from 'express';
|
2018-04-01 21:15:27 +02:00
|
|
|
import context from '../../remote/activitypub/renderer/context';
|
|
|
|
import renderNote from '../../remote/activitypub/renderer/note';
|
|
|
|
import renderOrderedCollection from '../../remote/activitypub/renderer/ordered-collection';
|
2018-04-02 06:15:53 +02:00
|
|
|
import config from '../../config';
|
2018-04-01 12:18:36 +02:00
|
|
|
import Post from '../../models/post';
|
2018-04-01 13:07:04 +02:00
|
|
|
import withUser from './with-user';
|
2018-04-01 12:18:36 +02:00
|
|
|
|
2018-04-05 10:52:46 +02:00
|
|
|
const app = express.Router();
|
2018-04-01 12:18:36 +02:00
|
|
|
|
2018-04-01 13:07:04 +02:00
|
|
|
app.get('/@:user/outbox', withUser(username => {
|
|
|
|
return `${config.url}/@${username}/inbox`;
|
|
|
|
}, async (user, req, res) => {
|
2018-04-01 12:18:36 +02:00
|
|
|
const posts = await Post.find({ userId: user._id }, {
|
|
|
|
limit: 20,
|
|
|
|
sort: { _id: -1 }
|
|
|
|
});
|
|
|
|
|
|
|
|
const renderedPosts = await Promise.all(posts.map(post => renderNote(user, post)));
|
2018-04-01 13:07:04 +02:00
|
|
|
const rendered = renderOrderedCollection(`${config.url}/@${user.username}/inbox`, user.postsCount, renderedPosts);
|
2018-04-01 12:18:36 +02:00
|
|
|
rendered['@context'] = context;
|
|
|
|
|
|
|
|
res.json(rendered);
|
2018-04-01 13:07:04 +02:00
|
|
|
}));
|
2018-04-01 12:18:36 +02:00
|
|
|
|
|
|
|
export default app;
|