summaryrefslogtreecommitdiff
path: root/src/api/endpoints/posts/create.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-06-07 01:20:07 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-06-07 01:20:07 +0900
commit6c4baf69ff6183710032e625bffb274b9f96040b (patch)
treeded9d74505d8e2288dacb430d71a16042ee92fbe /src/api/endpoints/posts/create.ts
parentWIP #161 (diff)
downloadsharkey-6c4baf69ff6183710032e625bffb274b9f96040b.tar.gz
sharkey-6c4baf69ff6183710032e625bffb274b9f96040b.tar.bz2
sharkey-6c4baf69ff6183710032e625bffb274b9f96040b.zip
WIP #161
Diffstat (limited to 'src/api/endpoints/posts/create.ts')
-rw-r--r--src/api/endpoints/posts/create.ts54
1 files changed, 53 insertions, 1 deletions
diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts
index 7f2dfc6ecb..eb979402c4 100644
--- a/src/api/endpoints/posts/create.ts
+++ b/src/api/endpoints/posts/create.ts
@@ -9,8 +9,10 @@ import { isValidText } from '../../models/post';
import User from '../../models/user';
import Following from '../../models/following';
import DriveFile from '../../models/drive-file';
+import Watching from '../../models/post-watching';
import serialize from '../../serializers/post';
import notify from '../../common/notify';
+import watch from '../../common/watch-post';
import event from '../../event';
import config from '../../../conf';
@@ -177,7 +179,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
// Reponse
res(postObj);
- // --------------------------------
+ // -----------------------------------------------------------
// Post processes
User.update({ _id: user._id }, {
@@ -240,6 +242,31 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
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
addMention(inReplyToPost.user_id, 'reply');
}
@@ -252,6 +279,31 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
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 (text) {
// Add mention