summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/notes
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-07-06 20:40:44 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-07-06 20:40:44 +0900
commita81a34cd765b1b226a6ad1382e3c076572aa1dd9 (patch)
tree40783fb02404f4291e83237e265ed200ce816aa2 /src/server/api/endpoints/notes
parentwip (diff)
downloadsharkey-a81a34cd765b1b226a6ad1382e3c076572aa1dd9.tar.gz
sharkey-a81a34cd765b1b226a6ad1382e3c076572aa1dd9.tar.bz2
sharkey-a81a34cd765b1b226a6ad1382e3c076572aa1dd9.zip
新形式に移行
Diffstat (limited to 'src/server/api/endpoints/notes')
-rw-r--r--src/server/api/endpoints/notes/timeline.ts121
1 files changed, 77 insertions, 44 deletions
diff --git a/src/server/api/endpoints/notes/timeline.ts b/src/server/api/endpoints/notes/timeline.ts
index 9144c6625c..eb491bc8eb 100644
--- a/src/server/api/endpoints/notes/timeline.ts
+++ b/src/server/api/endpoints/notes/timeline.ts
@@ -4,47 +4,80 @@ import Mute from '../../../../models/mute';
import { getFriends } from '../../common/get-friends';
import { pack } from '../../../../models/note';
import { ILocalUser } from '../../../../models/user';
+import getParams from '../../get-params';
-/**
- * Get timeline of myself
- */
-export default async (params: any, user: ILocalUser) => {
- // Get 'limit' parameter
- const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
- if (limitErr) throw 'invalid limit param';
+export const meta = {
+ name: 'notes/timeline',
- // Get 'sinceId' parameter
- const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
- if (sinceIdErr) throw 'invalid sinceId param';
+ desc: {
+ ja: 'タイムラインを取得します。'
+ },
- // Get 'untilId' parameter
- const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
- if (untilIdErr) throw 'invalid untilId param';
+ params: {
+ limit: $.num.optional.range(1, 100).note({
+ default: 10,
+ desc: {
+ ja: '最大数'
+ }
+ }),
- // Get 'sinceDate' parameter
- const [sinceDate, sinceDateErr] = $.num.optional.get(params.sinceDate);
- if (sinceDateErr) throw 'invalid sinceDate param';
+ sinceId: $.type(ID).optional.note({
+ desc: {
+ ja: '指定すると、この投稿を基点としてより新しい投稿を取得します'
+ }
+ }),
- // Get 'untilDate' parameter
- const [untilDate, untilDateErr] = $.num.optional.get(params.untilDate);
- if (untilDateErr) throw 'invalid untilDate param';
+ untilId: $.type(ID).optional.note({
+ desc: {
+ ja: '指定すると、この投稿を基点としてより古い投稿を取得します'
+ }
+ }),
- // Check if only one of sinceId, untilId, sinceDate, untilDate specified
- if ([sinceId, untilId, sinceDate, untilDate].filter(x => x != null).length > 1) {
- throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified';
- }
+ sinceDate: $.num.optional.note({
+ desc: {
+ ja: '指定した時間を基点としてより新しい投稿を取得します。数値は、1970 年 1 月 1 日 00:00:00 UTC から指定した日時までの経過時間をミリ秒単位で表します。'
+ }
+ }),
- // Get 'includeMyRenotes' parameter
- const [includeMyRenotes = true, includeMyRenotesErr] = $.bool.optional.get(params.includeMyRenotes);
- if (includeMyRenotesErr) throw 'invalid includeMyRenotes param';
+ untilDate: $.num.optional.note({
+ desc: {
+ ja: '指定した時間を基点としてより古い投稿を取得します。数値は、1970 年 1 月 1 日 00:00:00 UTC から指定した日時までの経過時間をミリ秒単位で表します。'
+ }
+ }),
- // Get 'includeRenotedMyNotes' parameter
- const [includeRenotedMyNotes = true, includeRenotedMyNotesErr] = $.bool.optional.get(params.includeRenotedMyNotes);
- if (includeRenotedMyNotesErr) throw 'invalid includeRenotedMyNotes param';
+ includeMyRenotes: $.bool.optional.note({
+ default: true,
+ desc: {
+ ja: '自分の行ったRenoteを含めるかどうか'
+ }
+ }),
- // Get 'mediaOnly' parameter
- const [mediaOnly, mediaOnlyErr] = $.bool.optional.get(params.mediaOnly);
- if (mediaOnlyErr) throw 'invalid mediaOnly param';
+ includeRenotedMyNotes: $.bool.optional.note({
+ default: true,
+ desc: {
+ ja: 'Renoteされた自分の投稿を含めるかどうか'
+ }
+ }),
+
+ mediaOnly: $.bool.optional.note({
+ desc: {
+ ja: 'true にすると、メディアが添付された投稿だけ取得します'
+ }
+ }),
+ }
+};
+
+/**
+ * Get timeline of myself
+ */
+export default async (params: any, user: ILocalUser) => {
+ const [ps, psErr] = getParams(meta, params);
+ if (psErr) throw psErr;
+
+ // Check if only one of sinceId, untilId, sinceDate, untilDate specified
+ if ([ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate].filter(x => x != null).length > 1) {
+ throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified';
+ }
const [followings, mutedUserIds] = await Promise.all([
// フォローを取得
@@ -107,7 +140,7 @@ export default async (params: any, user: ILocalUser) => {
// つまり、「『自分の投稿かつRenote』ではない」を「『自分の投稿ではない』または『Renoteではない』」と表現します。
// for details: https://en.wikipedia.org/wiki/De_Morgan%27s_laws
- if (includeMyRenotes === false) {
+ if (ps.includeMyRenotes === false) {
query.$and.push({
$or: [{
userId: { $ne: user._id }
@@ -123,7 +156,7 @@ export default async (params: any, user: ILocalUser) => {
});
}
- if (includeRenotedMyNotes === false) {
+ if (ps.includeRenotedMyNotes === false) {
query.$and.push({
$or: [{
'_renote.userId': { $ne: user._id }
@@ -139,29 +172,29 @@ export default async (params: any, user: ILocalUser) => {
});
}
- if (mediaOnly) {
+ if (ps.mediaOnly) {
query.$and.push({
mediaIds: { $exists: true, $ne: [] }
});
}
- if (sinceId) {
+ if (ps.sinceId) {
sort._id = 1;
query._id = {
- $gt: sinceId
+ $gt: ps.sinceId
};
- } else if (untilId) {
+ } else if (ps.untilId) {
query._id = {
- $lt: untilId
+ $lt: ps.untilId
};
- } else if (sinceDate) {
+ } else if (ps.sinceDate) {
sort._id = 1;
query.createdAt = {
- $gt: new Date(sinceDate)
+ $gt: new Date(ps.sinceDate)
};
- } else if (untilDate) {
+ } else if (ps.untilDate) {
query.createdAt = {
- $lt: new Date(untilDate)
+ $lt: new Date(ps.untilDate)
};
}
//#endregion
@@ -169,7 +202,7 @@ export default async (params: any, user: ILocalUser) => {
// Issue query
const timeline = await Note
.find(query, {
- limit: limit,
+ limit: ps.limit,
sort: sort
});