summaryrefslogtreecommitdiff
path: root/src/api/endpoints/posts/timeline.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/endpoints/posts/timeline.ts')
-rw-r--r--src/api/endpoints/posts/timeline.ts55
1 files changed, 37 insertions, 18 deletions
diff --git a/src/api/endpoints/posts/timeline.ts b/src/api/endpoints/posts/timeline.ts
index 0d08b95463..c41cfdb8bd 100644
--- a/src/api/endpoints/posts/timeline.ts
+++ b/src/api/endpoints/posts/timeline.ts
@@ -4,9 +4,10 @@
import $ from 'cafy';
import rap from '@prezzemolo/rap';
import Post from '../../models/post';
+import Mute from '../../models/mute';
import ChannelWatching from '../../models/channel-watching';
import getFriends from '../../common/get-friends';
-import serialize from '../../serializers/post';
+import { pack } from '../../models/post';
/**
* Get timeline of myself
@@ -25,32 +26,40 @@ module.exports = async (params, user, app) => {
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) throw 'invalid since_id param';
- // Get 'max_id' parameter
- const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
- if (maxIdErr) throw 'invalid max_id param';
+ // Get 'until_id' parameter
+ const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
+ if (untilIdErr) throw 'invalid until_id param';
// Get 'since_date' parameter
const [sinceDate, sinceDateErr] = $(params.since_date).optional.number().$;
if (sinceDateErr) throw 'invalid since_date param';
- // Get 'max_date' parameter
- const [maxDate, maxDateErr] = $(params.max_date).optional.number().$;
- if (maxDateErr) throw 'invalid max_date param';
+ // Get 'until_date' parameter
+ const [untilDate, untilDateErr] = $(params.until_date).optional.number().$;
+ if (untilDateErr) throw 'invalid until_date param';
- // Check if only one of since_id, max_id, since_date, max_date specified
- if ([sinceId, maxId, sinceDate, maxDate].filter(x => x != null).length > 1) {
- throw 'only one of since_id, max_id, since_date, max_date can be specified';
+ // Check if only one of since_id, until_id, since_date, until_date specified
+ if ([sinceId, untilId, sinceDate, untilDate].filter(x => x != null).length > 1) {
+ throw 'only one of since_id, until_id, since_date, until_date can be specified';
}
- const { followingIds, watchingChannelIds } = await rap({
+ const { followingIds, watchingChannelIds, mutedUserIds } = await rap({
// ID list of the user itself and other users who the user follows
followingIds: getFriends(user._id),
+
// Watchしているチャンネルを取得
watchingChannelIds: ChannelWatching.find({
user_id: user._id,
// 削除されたドキュメントは除く
deleted_at: { $exists: false }
- }).then(watches => watches.map(w => w.channel_id))
+ }).then(watches => watches.map(w => w.channel_id)),
+
+ // ミュートしているユーザーを取得
+ mutedUserIds: Mute.find({
+ muter_id: user._id,
+ // 削除されたドキュメントは除く
+ deleted_at: { $exists: false }
+ }).then(ms => ms.map(m => m.mutee_id))
});
//#region Construct query
@@ -77,7 +86,17 @@ module.exports = async (params, user, app) => {
channel_id: {
$in: watchingChannelIds
}
- }]
+ }],
+ // mute
+ user_id: {
+ $nin: mutedUserIds
+ },
+ '_reply.user_id': {
+ $nin: mutedUserIds
+ },
+ '_repost.user_id': {
+ $nin: mutedUserIds
+ },
} as any;
if (sinceId) {
@@ -85,18 +104,18 @@ module.exports = async (params, user, app) => {
query._id = {
$gt: sinceId
};
- } else if (maxId) {
+ } else if (untilId) {
query._id = {
- $lt: maxId
+ $lt: untilId
};
} else if (sinceDate) {
sort._id = 1;
query.created_at = {
$gt: new Date(sinceDate)
};
- } else if (maxDate) {
+ } else if (untilDate) {
query.created_at = {
- $lt: new Date(maxDate)
+ $lt: new Date(untilDate)
};
}
//#endregion
@@ -109,5 +128,5 @@ module.exports = async (params, user, app) => {
});
// Serialize
- return await Promise.all(timeline.map(post => serialize(post, user)));
+ return await Promise.all(timeline.map(post => pack(post, user)));
};