2018-04-01 10:18:36 +00:00
|
|
|
import renderDocument from './document';
|
|
|
|
import renderHashtag from './hashtag';
|
2018-04-02 04:15:53 +00:00
|
|
|
import config from '../../../config';
|
2018-04-01 19:15:27 +00:00
|
|
|
import DriveFile from '../../../models/drive-file';
|
|
|
|
import Post from '../../../models/post';
|
|
|
|
import User from '../../../models/user';
|
2018-04-01 10:18:36 +00:00
|
|
|
|
|
|
|
export default async (user, post) => {
|
|
|
|
const promisedFiles = DriveFile.find({ _id: { $in: post.mediaIds } });
|
|
|
|
let inReplyTo;
|
|
|
|
|
|
|
|
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}`;
|
|
|
|
|
|
|
|
return {
|
2018-04-02 16:37:11 +00:00
|
|
|
id: `${attributedTo}/${post._id}`,
|
2018-04-01 10:18:36 +00:00
|
|
|
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(renderDocument),
|
|
|
|
tag: post.tags.map(renderHashtag)
|
|
|
|
};
|
|
|
|
};
|