summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/notes/replies.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2018-06-18 14:43:56 +0900
committerGitHub <noreply@github.com>2018-06-18 14:43:56 +0900
commit5d3943ffa8cb4090c5c111397e266d255cc2212b (patch)
tree46f692fb21005bdc89499ea012c2436e8a2e90c0 /src/server/api/endpoints/notes/replies.ts
parentNew translations ja.yml (Spanish) (diff)
parentyatta (diff)
downloadmisskey-5d3943ffa8cb4090c5c111397e266d255cc2212b.tar.gz
misskey-5d3943ffa8cb4090c5c111397e266d255cc2212b.tar.bz2
misskey-5d3943ffa8cb4090c5c111397e266d255cc2212b.zip
Merge branch 'master' into l10n_master
Diffstat (limited to 'src/server/api/endpoints/notes/replies.ts')
-rw-r--r--src/server/api/endpoints/notes/replies.ts29
1 files changed, 5 insertions, 24 deletions
diff --git a/src/server/api/endpoints/notes/replies.ts b/src/server/api/endpoints/notes/replies.ts
index 11d221d8f7..4aaf1d322b 100644
--- a/src/server/api/endpoints/notes/replies.ts
+++ b/src/server/api/endpoints/notes/replies.ts
@@ -1,17 +1,11 @@
-/**
- * Module dependencies
- */
import $ from 'cafy'; import ID from '../../../../cafy-id';
import Note, { pack } from '../../../../models/note';
+import { ILocalUser } from '../../../../models/user';
/**
- * Show a replies of a note
- *
- * @param {any} params
- * @param {any} user
- * @return {Promise<any>}
+ * Get replies of a note
*/
-module.exports = (params, user) => new Promise(async (res, rej) => {
+module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
// Get 'noteId' parameter
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
if (noteIdErr) return rej('invalid noteId param');
@@ -24,10 +18,6 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
if (offsetErr) return rej('invalid offset param');
- // Get 'sort' parameter
- const [sort = 'desc', sortError] = $.str.optional().or('desc asc').get(params.sort);
- if (sortError) return rej('invalid sort param');
-
// Lookup note
const note = await Note.findOne({
_id: noteId
@@ -37,17 +27,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
return rej('note not found');
}
- // Issue query
- const replies = await Note
- .find({ replyId: note._id }, {
- limit: limit,
- skip: offset,
- sort: {
- _id: sort == 'asc' ? 1 : -1
- }
- });
+ const ids = (note._replyIds || []).slice(offset, offset + limit);
// Serialize
- res(await Promise.all(replies.map(async note =>
- await pack(note, user))));
+ res(await Promise.all(ids.map(id => pack(id, user))));
});