Implement outbox
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import * as express from 'express';
|
||||
import context from '../../common/remote/activitypub/context';
|
||||
import context from '../../common/remote/activitypub/renderer/context';
|
||||
import render from '../../common/remote/activitypub/renderer/note';
|
||||
import parseAcct from '../../common/user/parse-acct';
|
||||
import config from '../../conf';
|
||||
import DriveFile from '../../models/drive-file';
|
||||
import Post from '../../models/post';
|
||||
import User from '../../models/user';
|
||||
|
||||
@@ -36,50 +35,10 @@ app.get('/@:user/:post', async (req, res, next) => {
|
||||
return res.sendStatus(404);
|
||||
}
|
||||
|
||||
const promisedFiles = DriveFile.find({ _id: { $in: post.mediaIds } });
|
||||
let inReplyTo;
|
||||
const rendered = await render(user, post);
|
||||
rendered['@context'] = context;
|
||||
|
||||
if (post.replyId) {
|
||||
const inReplyToPost = await Post.findOne({
|
||||
_id: post.replyId,
|
||||
});
|
||||
|
||||
if (inReplyToPost !== null) {
|
||||
const inReplyToUser = await User.findOne({
|
||||
_id: post.userId,
|
||||
});
|
||||
|
||||
if (inReplyToUser !== null) {
|
||||
inReplyTo = `${config.url}@${inReplyToUser.username}/${inReplyToPost._id}`;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
inReplyTo = null;
|
||||
}
|
||||
|
||||
const attributedTo = `${config.url}/@${user.username}`;
|
||||
|
||||
res.json({
|
||||
'@context': context,
|
||||
id: `${attributedTo}/${post._id}`,
|
||||
type: 'Note',
|
||||
attributedTo,
|
||||
content: post.textHtml,
|
||||
published: post.createdAt.toISOString(),
|
||||
to: 'https://www.w3.org/ns/activitystreams#Public',
|
||||
cc: `${attributedTo}/followers`,
|
||||
inReplyTo,
|
||||
attachment: (await promisedFiles).map(({ _id, contentType }) => ({
|
||||
type: 'Document',
|
||||
mediaType: contentType,
|
||||
url: `${config.drive_url}/${_id}`
|
||||
})),
|
||||
tag: post.tags.map(tag => ({
|
||||
type: 'Hashtag',
|
||||
href: `${config.url}/search?q=#${encodeURIComponent(tag)}`,
|
||||
name: '#' + tag
|
||||
}))
|
||||
});
|
||||
res.json(rendered);
|
||||
});
|
||||
|
||||
export default app;
|
||||
|
Reference in New Issue
Block a user