summaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/api')
-rw-r--r--src/api/common/watch-post.ts11
-rw-r--r--src/api/endpoints/posts/create.ts54
-rw-r--r--src/api/endpoints/posts/polls/vote.ts2
-rw-r--r--src/api/endpoints/posts/reactions/create.ts2
4 files changed, 63 insertions, 6 deletions
diff --git a/src/api/common/watch-post.ts b/src/api/common/watch-post.ts
index 9f5e7a9130..1a50f0edaa 100644
--- a/src/api/common/watch-post.ts
+++ b/src/api/common/watch-post.ts
@@ -1,10 +1,15 @@
import * as mongodb from 'mongodb';
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
const exist = await Watching.findOne({
- post_id: post,
+ post_id: (post as any)._id,
user_id: me,
deleted_at: { $exists: false }
});
@@ -15,7 +20,7 @@ export default async (me: mongodb.ObjectID, post: mongodb.ObjectID) => {
await Watching.insert({
created_at: new Date(),
- post_id: post,
+ post_id: (post as any)._id,
user_id: me
});
};
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
diff --git a/src/api/endpoints/posts/polls/vote.ts b/src/api/endpoints/posts/polls/vote.ts
index 7bd9119fcb..5a4fd1c268 100644
--- a/src/api/endpoints/posts/polls/vote.ts
+++ b/src/api/endpoints/posts/polls/vote.ts
@@ -102,7 +102,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// この投稿をWatchする
// TODO: ユーザーが「投票したときに自動でWatchする」設定を
// オフにしていた場合はしない
- watch(user._id, post._id);
+ watch(user._id, post);
});
function findWithAttr(array, attr, value) {
diff --git a/src/api/endpoints/posts/reactions/create.ts b/src/api/endpoints/posts/reactions/create.ts
index 7cae3830e0..eecb928123 100644
--- a/src/api/endpoints/posts/reactions/create.ts
+++ b/src/api/endpoints/posts/reactions/create.ts
@@ -111,5 +111,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// この投稿をWatchする
// TODO: ユーザーが「リアクションしたときに自動でWatchする」設定を
// オフにしていた場合はしない
- watch(user._id, post._id);
+ watch(user._id, post);
});