Clean up
This commit is contained in:
		@@ -4,7 +4,6 @@
 | 
			
		||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
 | 
			
		||||
import Note, { INote, isValidText, isValidCw, pack } from '../../../../models/note';
 | 
			
		||||
import User, { ILocalUser } from '../../../../models/user';
 | 
			
		||||
import Channel, { IChannel } from '../../../../models/channel';
 | 
			
		||||
import DriveFile from '../../../../models/drive-file';
 | 
			
		||||
import create from '../../../../services/note/create';
 | 
			
		||||
import { IApp } from '../../../../models/app';
 | 
			
		||||
@@ -89,7 +88,6 @@ module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res
 | 
			
		||||
	if (renoteIdErr) return rej('invalid renoteId');
 | 
			
		||||
 | 
			
		||||
	let renote: INote = null;
 | 
			
		||||
	let isQuote = false;
 | 
			
		||||
	if (renoteId !== undefined) {
 | 
			
		||||
		// Fetch renote to note
 | 
			
		||||
		renote = await Note.findOne({
 | 
			
		||||
@@ -101,8 +99,6 @@ module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res
 | 
			
		||||
		} else if (renote.renoteId && !renote.text && !renote.mediaIds) {
 | 
			
		||||
			return rej('cannot renote to renote');
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		isQuote = text != null || files != null;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Get 'replyId' parameter
 | 
			
		||||
@@ -126,47 +122,6 @@ module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Get 'channelId' parameter
 | 
			
		||||
	const [channelId, channelIdErr] = $.type(ID).optional().get(params.channelId);
 | 
			
		||||
	if (channelIdErr) return rej('invalid channelId');
 | 
			
		||||
 | 
			
		||||
	let channel: IChannel = null;
 | 
			
		||||
	if (channelId !== undefined) {
 | 
			
		||||
		// Fetch channel
 | 
			
		||||
		channel = await Channel.findOne({
 | 
			
		||||
			_id: channelId
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		if (channel === null) {
 | 
			
		||||
			return rej('channel not found');
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// 返信対象の投稿がこのチャンネルじゃなかったらダメ
 | 
			
		||||
		if (reply && !channelId.equals(reply.channelId)) {
 | 
			
		||||
			return rej('チャンネル内部からチャンネル外部の投稿に返信することはできません');
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// Renote対象の投稿がこのチャンネルじゃなかったらダメ
 | 
			
		||||
		if (renote && !channelId.equals(renote.channelId)) {
 | 
			
		||||
			return rej('チャンネル内部からチャンネル外部の投稿をRenoteすることはできません');
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// 引用ではないRenoteはダメ
 | 
			
		||||
		if (renote && !isQuote) {
 | 
			
		||||
			return rej('チャンネル内部では引用ではないRenoteをすることはできません');
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		// 返信対象の投稿がチャンネルへの投稿だったらダメ
 | 
			
		||||
		if (reply && reply.channelId != null) {
 | 
			
		||||
			return rej('チャンネル外部からチャンネル内部の投稿に返信することはできません');
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// Renote対象の投稿がチャンネルへの投稿だったらダメ
 | 
			
		||||
		if (renote && renote.channelId != null) {
 | 
			
		||||
			return rej('チャンネル外部からチャンネル内部の投稿をRenoteすることはできません');
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Get 'poll' parameter
 | 
			
		||||
	const [poll, pollErr] = $.obj.optional().strict()
 | 
			
		||||
		.have('choices', $.arr($.str)
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,6 @@
 | 
			
		||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
 | 
			
		||||
import Note from '../../../../models/note';
 | 
			
		||||
import Mute from '../../../../models/mute';
 | 
			
		||||
import ChannelWatching from '../../../../models/channel-watching';
 | 
			
		||||
import { getFriends } from '../../common/get-friends';
 | 
			
		||||
import { pack } from '../../../../models/note';
 | 
			
		||||
 | 
			
		||||
@@ -45,18 +44,11 @@ module.exports = async (params, user, app) => {
 | 
			
		||||
	const [includeRenotedMyNotes = true, includeRenotedMyNotesErr] = $.bool.optional().get(params.includeRenotedMyNotes);
 | 
			
		||||
	if (includeRenotedMyNotesErr) throw 'invalid includeRenotedMyNotes param';
 | 
			
		||||
 | 
			
		||||
	const [followings, watchingChannelIds, mutedUserIds] = await Promise.all([
 | 
			
		||||
	const [followings, mutedUserIds] = await Promise.all([
 | 
			
		||||
		// フォローを取得
 | 
			
		||||
		// Fetch following
 | 
			
		||||
		getFriends(user._id),
 | 
			
		||||
 | 
			
		||||
		// Watchしているチャンネルを取得
 | 
			
		||||
		ChannelWatching.find({
 | 
			
		||||
			userId: user._id,
 | 
			
		||||
			// 削除されたドキュメントは除く
 | 
			
		||||
			deletedAt: { $exists: false }
 | 
			
		||||
		}).then(watches => watches.map(w => w.channelId)),
 | 
			
		||||
 | 
			
		||||
		// ミュートしているユーザーを取得
 | 
			
		||||
		Mute.find({
 | 
			
		||||
			muterId: user._id
 | 
			
		||||
@@ -93,26 +85,9 @@ module.exports = async (params, user, app) => {
 | 
			
		||||
 | 
			
		||||
	const query = {
 | 
			
		||||
		$and: [{
 | 
			
		||||
			$or: [{
 | 
			
		||||
				$and: [{
 | 
			
		||||
					// フォローしている人のタイムラインへの投稿
 | 
			
		||||
					$or: followQuery
 | 
			
		||||
				}, {
 | 
			
		||||
					// 「タイムラインへの」投稿に限定するためにチャンネルが指定されていないもののみに限る
 | 
			
		||||
					$or: [{
 | 
			
		||||
						channelId: {
 | 
			
		||||
							$exists: false
 | 
			
		||||
						}
 | 
			
		||||
					}, {
 | 
			
		||||
						channelId: null
 | 
			
		||||
					}]
 | 
			
		||||
				}]
 | 
			
		||||
			}, {
 | 
			
		||||
				// Watchしているチャンネルへの投稿
 | 
			
		||||
				channelId: {
 | 
			
		||||
					$in: watchingChannelIds
 | 
			
		||||
				}
 | 
			
		||||
			}],
 | 
			
		||||
			// フォローしている人の投稿
 | 
			
		||||
			$or: followQuery,
 | 
			
		||||
 | 
			
		||||
			// mute
 | 
			
		||||
			userId: {
 | 
			
		||||
				$nin: mutedUserIds
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user