summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/users/notes.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-09-05 23:55:51 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-09-05 23:55:51 +0900
commitb5ff2abdb9ee0c086c8970c738cce5d61761f8f5 (patch)
treec23a8e7e5bec3ea21167795fd008942127823d41 /src/server/api/endpoints/users/notes.ts
parent[WIP] Update welcome page (diff)
downloadmisskey-b5ff2abdb9ee0c086c8970c738cce5d61761f8f5.tar.gz
misskey-b5ff2abdb9ee0c086c8970c738cce5d61761f8f5.tar.bz2
misskey-b5ff2abdb9ee0c086c8970c738cce5d61761f8f5.zip
互換性のためのコードを追加 & #2623
Diffstat (limited to 'src/server/api/endpoints/users/notes.ts')
-rw-r--r--src/server/api/endpoints/users/notes.ts166
1 files changed, 112 insertions, 54 deletions
diff --git a/src/server/api/endpoints/users/notes.ts b/src/server/api/endpoints/users/notes.ts
index d894e52dba..42c31189d6 100644
--- a/src/server/api/endpoints/users/notes.ts
+++ b/src/server/api/endpoints/users/notes.ts
@@ -2,63 +2,121 @@ import $ from 'cafy'; import ID from '../../../../misc/cafy-id';
import getHostLower from '../../common/get-host-lower';
import Note, { pack } from '../../../../models/note';
import User, { ILocalUser } from '../../../../models/user';
+import getParams from '../../get-params';
-/**
- * Get notes of a user
- */
-export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => {
- // Get 'userId' parameter
- const [userId, userIdErr] = $.type(ID).optional.get(params.userId);
- if (userIdErr) return rej('invalid userId param');
+export const meta = {
+ desc: {
+ 'ja-JP': '指定したユーザーのタイムラインを取得します。'
+ },
- // Get 'username' parameter
- const [username, usernameErr] = $.str.optional.get(params.username);
- if (usernameErr) return rej('invalid username param');
+ params: {
+ userId: $.type(ID).optional.note({
+ desc: {
+ 'ja-JP': 'ユーザーID'
+ }
+ }),
- if (userId === undefined && username === undefined) {
- return rej('userId or username is required');
- }
+ username: $.str.optional.note({
+ desc: {
+ 'ja-JP': 'ユーザー名'
+ }
+ }),
+
+ host: $.str.optional.note({
+ }),
- // Get 'host' parameter
- const [host, hostErr] = $.str.optional.get(params.host);
- if (hostErr) return rej('invalid host param');
+ includeReplies: $.bool.optional.note({
+ default: true,
- // Get 'includeReplies' parameter
- const [includeReplies = true, includeRepliesErr] = $.bool.optional.get(params.includeReplies);
- if (includeRepliesErr) return rej('invalid includeReplies param');
+ desc: {
+ 'ja-JP': 'リプライを含めるか否か'
+ }
+ }),
- // Get 'withFiles' parameter
- const [withFiles = false, withFilesErr] = $.bool.optional.get(params.withFiles);
- if (withFilesErr) return rej('invalid withFiles param');
+ limit: $.num.optional.range(1, 100).note({
+ default: 10,
+ desc: {
+ 'ja-JP': '最大数'
+ }
+ }),
- // Get 'limit' parameter
- const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
- if (limitErr) return rej('invalid limit param');
+ sinceId: $.type(ID).optional.note({
+ desc: {
+ 'ja-JP': '指定すると、この投稿を基点としてより新しい投稿を取得します'
+ }
+ }),
- // Get 'sinceId' parameter
- const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
- if (sinceIdErr) return rej('invalid sinceId param');
+ untilId: $.type(ID).optional.note({
+ desc: {
+ 'ja-JP': '指定すると、この投稿を基点としてより古い投稿を取得します'
+ }
+ }),
- // Get 'untilId' parameter
- const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
- if (untilIdErr) return rej('invalid untilId param');
+ sinceDate: $.num.optional.note({
+ desc: {
+ 'ja-JP': '指定した時間を基点としてより新しい投稿を取得します。数値は、1970年1月1日 00:00:00 UTC から指定した日時までの経過時間をミリ秒単位で表します。'
+ }
+ }),
- // Get 'sinceDate' parameter
- const [sinceDate, sinceDateErr] = $.num.optional.get(params.sinceDate);
- if (sinceDateErr) throw 'invalid sinceDate param';
+ untilDate: $.num.optional.note({
+ desc: {
+ 'ja-JP': '指定した時間を基点としてより古い投稿を取得します。数値は、1970年1月1日 00:00:00 UTC から指定した日時までの経過時間をミリ秒単位で表します。'
+ }
+ }),
- // Get 'untilDate' parameter
- const [untilDate, untilDateErr] = $.num.optional.get(params.untilDate);
- if (untilDateErr) throw 'invalid untilDate param';
+ includeMyRenotes: $.bool.optional.note({
+ default: true,
+ desc: {
+ 'ja-JP': '自分の行ったRenoteを含めるかどうか'
+ }
+ }),
+
+ includeRenotedMyNotes: $.bool.optional.note({
+ default: true,
+ desc: {
+ 'ja-JP': 'Renoteされた自分の投稿を含めるかどうか'
+ }
+ }),
+
+ includeLocalRenotes: $.bool.optional.note({
+ default: true,
+ desc: {
+ 'ja-JP': 'Renoteされたローカルの投稿を含めるかどうか'
+ }
+ }),
+
+ withFiles: $.bool.optional.note({
+ default: false,
+ desc: {
+ 'ja-JP': 'true にすると、ファイルが添付された投稿だけ取得します'
+ }
+ }),
+
+ mediaOnly: $.bool.optional.note({
+ default: false,
+ desc: {
+ 'ja-JP': 'true にすると、ファイルが添付された投稿だけ取得します (このパラメータは廃止予定です。代わりに withFiles を使ってください。)'
+ }
+ }),
+ }
+};
+
+export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => {
+ const [ps, psErr] = getParams(meta, params);
+ if (psErr) throw psErr;
+
+ if (ps.userId === undefined && ps.username === undefined) {
+ return rej('userId or username is required');
+ }
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
- if ([sinceId, untilId, sinceDate, untilDate].filter(x => x != null).length > 1) {
+ 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 q = userId !== undefined
- ? { _id: userId }
- : { usernameLower: username.toLowerCase(), host: getHostLower(host) } ;
+ const q = ps.userId !== undefined
+ ? { _id: ps.userId }
+ : { usernameLower: ps.username.toLowerCase(), host: getHostLower(ps.host) } ;
// Lookup user
const user = await User.findOne(q, {
@@ -80,30 +138,32 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) =>
userId: user._id
} as any;
- 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)
};
}
- if (!includeReplies) {
+ if (!ps.includeReplies) {
query.replyId = null;
}
+ const withFiles = ps.withFiles != null ? ps.withFiles : ps.mediaOnly;
+
if (withFiles) {
query.fileIds = {
$exists: true,
@@ -115,12 +175,10 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) =>
// Issue query
const notes = await Note
.find(query, {
- limit: limit,
+ limit: ps.limit,
sort: sort
});
// Serialize
- res(await Promise.all(notes.map(async (note) =>
- await pack(note, me)
- )));
+ res(await Promise.all(notes.map(note => pack(note, me))));
});