summaryrefslogtreecommitdiff
path: root/src/api/endpoints/posts/create.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-11-01 19:33:08 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-11-01 19:33:08 +0900
commitd6b03c43eb818a5e13a8ad1ec69697e4600c5c2c (patch)
tree20302f7974e7939f2e498b07bd11c86bea4f7e82 /src/api/endpoints/posts/create.ts
parentv2799 (diff)
downloadsharkey-d6b03c43eb818a5e13a8ad1ec69697e4600c5c2c.tar.gz
sharkey-d6b03c43eb818a5e13a8ad1ec69697e4600c5c2c.tar.bz2
sharkey-d6b03c43eb818a5e13a8ad1ec69697e4600c5c2c.zip
Implement Channel Watching
Diffstat (limited to 'src/api/endpoints/posts/create.ts')
-rw-r--r--src/api/endpoints/posts/create.ts43
1 files changed, 27 insertions, 16 deletions
diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts
index b3fbdf6fa2..2326f7baf1 100644
--- a/src/api/endpoints/posts/create.ts
+++ b/src/api/endpoints/posts/create.ts
@@ -10,6 +10,7 @@ import { default as Channel, IChannel } from '../../models/channel';
import Following from '../../models/following';
import DriveFile from '../../models/drive-file';
import Watching from '../../models/post-watching';
+import ChannelWatching from '../../models/channel-watching';
import serialize from '../../serializers/post';
import notify from '../../common/notify';
import watch from '../../common/watch-post';
@@ -249,26 +250,11 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
}
}
- // TODO
+ // タイムラインへの投稿
if (!channel) {
// Publish event to myself's stream
event(user._id, 'post', postObj);
- }
- if (channel) {
- // Increment channel index(posts count)
- Channel.update({ _id: channel._id }, {
- $inc: {
- index: 1
- }
- });
-
- // Publish event to channel
- publishChannelStream(channel._id, 'post', postObj);
- }
-
- // TODO
- if (!channel) {
// Fetch all followers
const followers = await Following
.find({
@@ -285,6 +271,31 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
event(following.follower_id, 'post', postObj));
}
+ // チャンネルへの投稿
+ if (channel) {
+ // Increment channel index(posts count)
+ Channel.update({ _id: channel._id }, {
+ $inc: {
+ index: 1
+ }
+ });
+
+ // Publish event to channel
+ publishChannelStream(channel._id, 'post', postObj);
+
+ // Get channel watchers
+ const watches = await ChannelWatching.find({
+ channel_id: channel._id,
+ // 削除されたドキュメントは除く
+ deleted_at: { $exists: false }
+ });
+
+ // チャンネルの視聴者(のタイムライン)に配信
+ watches.forEach(w => {
+ event(w.user_id, 'post', postObj);
+ });
+ }
+
// Increment my posts count
User.update({ _id: user._id }, {
$inc: {