summaryrefslogtreecommitdiff
path: root/src/api/endpoints/posts/timeline.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/timeline.ts
parentv2799 (diff)
downloadsharkey-d6b03c43eb818a5e13a8ad1ec69697e4600c5c2c.tar.gz
sharkey-d6b03c43eb818a5e13a8ad1ec69697e4600c5c2c.tar.bz2
sharkey-d6b03c43eb818a5e13a8ad1ec69697e4600c5c2c.zip
Implement Channel Watching
Diffstat (limited to 'src/api/endpoints/posts/timeline.ts')
-rw-r--r--src/api/endpoints/posts/timeline.ts37
1 files changed, 28 insertions, 9 deletions
diff --git a/src/api/endpoints/posts/timeline.ts b/src/api/endpoints/posts/timeline.ts
index fe096442b4..aa5aff5ba5 100644
--- a/src/api/endpoints/posts/timeline.ts
+++ b/src/api/endpoints/posts/timeline.ts
@@ -3,6 +3,7 @@
*/
import $ from 'cafy';
import Post from '../../models/post';
+import ChannelWatching from '../../models/channel-watching';
import getFriends from '../../common/get-friends';
import serialize from '../../serializers/post';
@@ -32,26 +33,43 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
return rej('cannot set since_id and max_id');
}
- // ID list of the user $self and other users who the user follows
+ // ID list of the user itself and other users who the user follows
const followingIds = await getFriends(user._id);
- // Construct query
+ // Watchしているチャンネルを取得
+ const watches = await ChannelWatching.find({
+ user_id: user._id,
+ // 削除されたドキュメントは除く
+ deleted_at: { $exists: false }
+ });
+
+ //#region Construct query
const sort = {
_id: -1
};
+
const query = {
- user_id: {
- $in: followingIds
- },
- // TODO
$or: [{
+ // フォローしている人のタイムラインへの投稿
+ user_id: {
+ $in: followingIds
+ },
+ // 「タイムラインへの」投稿に限定するためにチャンネルが指定されていないもののみに限る
+ $or: [{
+ channel_id: {
+ $exists: false
+ }
+ }, {
+ channel_id: null
+ }]
+ }, {
+ // Watchしているチャンネルへの投稿
channel_id: {
- $exists: false
+ $in: watches.map(w => w.channel_id)
}
- }, {
- channel_id: null
}]
} as any;
+
if (sinceId) {
sort._id = 1;
query._id = {
@@ -62,6 +80,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
$lt: maxId
};
}
+ //#endregion
// Issue query
const timeline = await Post