summaryrefslogtreecommitdiff
path: root/src/api/endpoints/posts/reactions/create.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/endpoints/posts/reactions/create.ts')
-rw-r--r--src/api/endpoints/posts/reactions/create.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/api/endpoints/posts/reactions/create.ts b/src/api/endpoints/posts/reactions/create.ts
index ba5b69ada3..7cae3830e0 100644
--- a/src/api/endpoints/posts/reactions/create.ts
+++ b/src/api/endpoints/posts/reactions/create.ts
@@ -4,7 +4,9 @@
import $ from 'cafy';
import Reaction from '../../../models/post-reaction';
import Post from '../../../models/post';
+import Watching from '../../../models/post-watching';
import notify from '../../../common/notify';
+import watch from '../../../common/watch-post';
import { publishPostStream } from '../../../event';
/**
@@ -84,4 +86,30 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
post_id: post._id,
reaction: reaction
});
+
+ // Fetch watchers
+ Watching
+ .find({
+ post_id: post._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, 'reaction', {
+ post_id: post._id,
+ reaction: reaction
+ });
+ });
+ });
+
+ // この投稿をWatchする
+ // TODO: ユーザーが「リアクションしたときに自動でWatchする」設定を
+ // オフにしていた場合はしない
+ watch(user._id, post._id);
});