<commit_before>import Channel from '../../models/channel';
import Following from '../../models/following';
import ChannelWatching from '../../models/channel-watching';
import Post, { pack } from '../../models/post';
import User, { isLocalUser } from '../../models/user';
import stream, { publishChannelStream } from '../../publishers/stream';
import context from '../../remote/activitypub/renderer/context';
import renderCreate from '../../remote/activitypub/renderer/create';
import renderNote from '../../remote/activitypub/renderer/note';
import request from '../../remote/request';

export default ({ data }) => Post.findOne({ _id: data.id }).then(post => {
	const promisedPostObj = pack(post);
	const promises = [];

	// タイムラインへの投稿
	if (!post.channelId) {
		promises.push(
			// Publish event to myself's stream
			promisedPostObj.then(postObj => {
				stream(post.userId, 'post', postObj);
			}),

			Promise.all([
				User.findOne({ _id: post.userId }),

				// Fetch all followers
				Following.aggregate([
					{
						$lookup: {
							from: 'users',
							localField: 'followerId',
							foreignField: '_id',
							as: 'follower'
						}
					},
					{
					$match: {
							followeeId: post.userId
						}
					}
				], {
					_id: false
				})
			]).then(([user, followers]) => Promise.all(followers.map(following => {
				if (isLocalUser(following.follower)) {
					// Publish event to followers stream
					return promisedPostObj.then(postObj => {
						stream(following.followerId, 'post', postObj);
					});
				}

				return renderNote(user, post).then(note => {
					const create = renderCreate(note);
					create['@context'] = context;
					return request(user, following.follower[0].account.inbox, create);
				});
			})))
		);
	}

	// チャンネルへの投稿<commit_msg>Improve readability<commit_after>import Channel from '../../models/channel';
import Following from '../../models/following';
import ChannelWatching from '../../models/channel-watching';
import Post, { pack } from '../../models/post';
import User, { isLocalUser } from '../../models/user';
import stream, { publishChannelStream } from '../../publishers/stream';
import context from '../../remote/activitypub/renderer/context';
import renderCreate from '../../remote/activitypub/renderer/create';
import renderNote from '../../remote/activitypub/renderer/note';
import request from '../../remote/request';

export default ({ data }) => Post.findOne({ _id: data.id }).then(post => {
	const promisedPostObj = pack(post);
	const promises = [];

	// タイムラインへの投稿
	if (!post.channelId) {
		promises.push(
			// Publish event to myself's stream
			promisedPostObj.then(postObj => {
				stream(post.userId, 'post', postObj);
			}),

			Promise.all([
				User.findOne({ _id: post.userId }),

				// Fetch all followers
				Following.aggregate([{
					$lookup: {
						from: 'users',
						localField: 'followerId',
						foreignField: '_id',
						as: 'follower'
					}
				}, {
					$match: {
						followeeId: post.userId
					}
				}], {
					_id: false
				})
			]).then(([user, followers]) => Promise.all(followers.map(following => {
				if (isLocalUser(following.follower)) {
					// Publish event to followers stream
					return promisedPostObj.then(postObj => {
						stream(following.followerId, 'post', postObj);
					});
				}

				return renderNote(user, post).then(note => {
					const create = renderCreate(note);
					create['@context'] = context;
					return request(user, following.follower[0].account.inbox, create);
				});
			})))
		);
	}

	// チャンネルへの投稿
{'fraction_non_alphanumeric': 0.17447769621682666, 'fraction_numerical': 0.000564652738565782, 'mean_word_length': 2.8679039301310043, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5982512', 'n_tokens_mistral': 1356, 'n_tokens_neox': 1103, 'n_words': 236}