WIP #161
This commit is contained in:
		| @@ -1,10 +1,15 @@ | |||||||
| import * as mongodb from 'mongodb'; | import * as mongodb from 'mongodb'; | ||||||
| import Watching from '../models/post-watching'; | import Watching from '../models/post-watching'; | ||||||
|  |  | ||||||
| export default async (me: mongodb.ObjectID, post: mongodb.ObjectID) => { | export default async (me: mongodb.ObjectID, post: object) => { | ||||||
|  | 	// 自分の投稿はwatchできない | ||||||
|  | 	if (me.equals((post as any).user_id)) { | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	// if watching now | 	// if watching now | ||||||
| 	const exist = await Watching.findOne({ | 	const exist = await Watching.findOne({ | ||||||
| 		post_id: post, | 		post_id: (post as any)._id, | ||||||
| 		user_id: me, | 		user_id: me, | ||||||
| 		deleted_at: { $exists: false } | 		deleted_at: { $exists: false } | ||||||
| 	}); | 	}); | ||||||
| @@ -15,7 +20,7 @@ export default async (me: mongodb.ObjectID, post: mongodb.ObjectID) => { | |||||||
|  |  | ||||||
| 	await Watching.insert({ | 	await Watching.insert({ | ||||||
| 		created_at: new Date(), | 		created_at: new Date(), | ||||||
| 		post_id: post, | 		post_id: (post as any)._id, | ||||||
| 		user_id: me | 		user_id: me | ||||||
| 	}); | 	}); | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -9,8 +9,10 @@ import { isValidText } from '../../models/post'; | |||||||
| import User from '../../models/user'; | import User from '../../models/user'; | ||||||
| import Following from '../../models/following'; | import Following from '../../models/following'; | ||||||
| import DriveFile from '../../models/drive-file'; | import DriveFile from '../../models/drive-file'; | ||||||
|  | import Watching from '../../models/post-watching'; | ||||||
| import serialize from '../../serializers/post'; | import serialize from '../../serializers/post'; | ||||||
| import notify from '../../common/notify'; | import notify from '../../common/notify'; | ||||||
|  | import watch from '../../common/watch-post'; | ||||||
| import event from '../../event'; | import event from '../../event'; | ||||||
| import config from '../../../conf'; | import config from '../../../conf'; | ||||||
|  |  | ||||||
| @@ -177,7 +179,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => { | |||||||
| 	// Reponse | 	// Reponse | ||||||
| 	res(postObj); | 	res(postObj); | ||||||
|  |  | ||||||
| 	// -------------------------------- | 	// ----------------------------------------------------------- | ||||||
| 	// Post processes | 	// Post processes | ||||||
|  |  | ||||||
| 	User.update({ _id: user._id }, { | 	User.update({ _id: user._id }, { | ||||||
| @@ -240,6 +242,31 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => { | |||||||
| 			post_id: post._id | 			post_id: post._id | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
|  | 		// Fetch watchers | ||||||
|  | 		Watching | ||||||
|  | 			.find({ | ||||||
|  | 				post_id: inReplyToPost._id, | ||||||
|  | 				user_id: { $ne: user._id }, | ||||||
|  | 				// 削除されたドキュメントは除く | ||||||
|  | 				deleted_at: { $exists: false } | ||||||
|  | 			}, { | ||||||
|  | 				fields: { | ||||||
|  | 					user_id: true | ||||||
|  | 				} | ||||||
|  | 			}) | ||||||
|  | 			.then(watchers => { | ||||||
|  | 				watchers.forEach(watcher => { | ||||||
|  | 					notify(watcher.user_id, user._id, 'reply', { | ||||||
|  | 						post_id: post._id | ||||||
|  | 					}); | ||||||
|  | 				}); | ||||||
|  | 			}); | ||||||
|  |  | ||||||
|  | 		// この投稿をWatchする | ||||||
|  | 		// TODO: ユーザーが「返信したときに自動でWatchする」設定を | ||||||
|  | 		//       オフにしていた場合はしない | ||||||
|  | 		watch(user._id, inReplyToPost); | ||||||
|  |  | ||||||
| 		// Add mention | 		// Add mention | ||||||
| 		addMention(inReplyToPost.user_id, 'reply'); | 		addMention(inReplyToPost.user_id, 'reply'); | ||||||
| 	} | 	} | ||||||
| @@ -252,6 +279,31 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => { | |||||||
| 			post_id: post._id | 			post_id: post._id | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
|  | 		// Fetch watchers | ||||||
|  | 		Watching | ||||||
|  | 			.find({ | ||||||
|  | 				post_id: repost._id, | ||||||
|  | 				user_id: { $ne: user._id }, | ||||||
|  | 				// 削除されたドキュメントは除く | ||||||
|  | 				deleted_at: { $exists: false } | ||||||
|  | 			}, { | ||||||
|  | 				fields: { | ||||||
|  | 					user_id: true | ||||||
|  | 				} | ||||||
|  | 			}) | ||||||
|  | 			.then(watchers => { | ||||||
|  | 				watchers.forEach(watcher => { | ||||||
|  | 					notify(watcher.user_id, user._id, type, { | ||||||
|  | 						post_id: post._id | ||||||
|  | 					}); | ||||||
|  | 				}); | ||||||
|  | 			}); | ||||||
|  |  | ||||||
|  | 		// この投稿をWatchする | ||||||
|  | 		// TODO: ユーザーが「Repostしたときに自動でWatchする」設定を | ||||||
|  | 		//       オフにしていた場合はしない | ||||||
|  | 		watch(user._id, repost); | ||||||
|  |  | ||||||
| 		// If it is quote repost | 		// If it is quote repost | ||||||
| 		if (text) { | 		if (text) { | ||||||
| 			// Add mention | 			// Add mention | ||||||
|   | |||||||
| @@ -102,7 +102,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => { | |||||||
| 	// この投稿をWatchする | 	// この投稿をWatchする | ||||||
| 	// TODO: ユーザーが「投票したときに自動でWatchする」設定を | 	// TODO: ユーザーが「投票したときに自動でWatchする」設定を | ||||||
| 	//       オフにしていた場合はしない | 	//       オフにしていた場合はしない | ||||||
| 	watch(user._id, post._id); | 	watch(user._id, post); | ||||||
| }); | }); | ||||||
|  |  | ||||||
| function findWithAttr(array, attr, value) { | function findWithAttr(array, attr, value) { | ||||||
|   | |||||||
| @@ -111,5 +111,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => { | |||||||
| 	// この投稿をWatchする | 	// この投稿をWatchする | ||||||
| 	// TODO: ユーザーが「リアクションしたときに自動でWatchする」設定を | 	// TODO: ユーザーが「リアクションしたときに自動でWatchする」設定を | ||||||
| 	//       オフにしていた場合はしない | 	//       オフにしていた場合はしない | ||||||
| 	watch(user._id, post._id); | 	watch(user._id, post); | ||||||
| }); | }); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 syuilo
					syuilo