summaryrefslogtreecommitdiff
path: root/src/api/endpoints/posts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-11-11 10:58:13 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-11-11 10:58:13 +0900
commitba85942f76c0b7c0b458b48289569ada9aee2be1 (patch)
tree23071eb2af4f3d3905fd656a1fd0f59adbc2fec8 /src/api/endpoints/posts
parentv3006 (diff)
downloadsharkey-ba85942f76c0b7c0b458b48289569ada9aee2be1.tar.gz
sharkey-ba85942f76c0b7c0b458b48289569ada9aee2be1.tar.bz2
sharkey-ba85942f76c0b7c0b458b48289569ada9aee2be1.zip
#905
Diffstat (limited to 'src/api/endpoints/posts')
-rw-r--r--src/api/endpoints/posts/timeline.ts23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/api/endpoints/posts/timeline.ts b/src/api/endpoints/posts/timeline.ts
index 7af435e82a..0d08b95463 100644
--- a/src/api/endpoints/posts/timeline.ts
+++ b/src/api/endpoints/posts/timeline.ts
@@ -29,9 +29,17 @@ module.exports = async (params, user, app) => {
const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
if (maxIdErr) throw 'invalid max_id param';
- // Check if both of since_id and max_id is specified
- if (sinceId && maxId) {
- throw 'cannot set since_id and max_id';
+ // 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';
+
+ // 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';
}
const { followingIds, watchingChannelIds } = await rap({
@@ -81,6 +89,15 @@ module.exports = async (params, user, app) => {
query._id = {
$lt: maxId
};
+ } else if (sinceDate) {
+ sort._id = 1;
+ query.created_at = {
+ $gt: new Date(sinceDate)
+ };
+ } else if (maxDate) {
+ query.created_at = {
+ $lt: new Date(maxDate)
+ };
}
//#endregion