2018-04-01 05:18:36 -05:00
|
|
|
import * as express from 'express';
|
2018-04-01 14:15:27 -05: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-01 23:15:53 -05:00
|
|
|
import config from '../../config';
|
2018-04-07 12:30:37 -05:00
|
|
|
import Note from '../../models/note';
|
2018-04-01 06:07:04 -05:00
|
|
|
import withUser from './with-user';
|
2018-04-01 05:18:36 -05:00
|
|
|
|
2018-04-05 03:52:46 -05:00
|
|
|
const app = express.Router();
|
2018-04-01 05:18:36 -05:00
|
|
|
|
2018-04-01 06:07:04 -05:00
|
|
|
app.get('/@:user/outbox', withUser(username => {
|
|
|
|
return `${config.url}/@${username}/inbox`;
|
|
|
|
}, async (user, req, res) => {
|
2018-04-07 12:30:37 -05:00
|
|
|
const notes = await Note.find({ userId: user._id }, {
|
2018-04-01 05:18:36 -05:00
|
|
|
limit: 20,
|
|
|
|
sort: { _id: -1 }
|
|
|
|
});
|
|
|
|
|
2018-04-07 12:30:37 -05:00
|
|
|
const renderedNotes = await Promise.all(notes.map(note => renderNote(user, note)));
|
|
|
|
const rendered = renderOrderedCollection(`${config.url}/@${user.username}/inbox`, user.notesCount, renderedNotes);
|
2018-04-01 05:18:36 -05:00
|
|
|
rendered['@context'] = context;
|
|
|
|
|
|
|
|
res.json(rendered);
|
2018-04-01 06:07:04 -05:00
|
|
|
}));
|
2018-04-01 05:18:36 -05:00
|
|
|
|
|
|
|
export default app;
|