summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/notes.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/api/endpoints/notes.ts')
-rw-r--r--src/server/api/endpoints/notes.ts58
1 files changed, 16 insertions, 42 deletions
diff --git a/src/server/api/endpoints/notes.ts b/src/server/api/endpoints/notes.ts
index 835c515cfe..10f6e39845 100644
--- a/src/server/api/endpoints/notes.ts
+++ b/src/server/api/endpoints/notes.ts
@@ -1,7 +1,8 @@
import $ from 'cafy';
-import ID, { transform } from '../../../misc/cafy-id';
-import Note, { packMany } from '../../../models/note';
+import { ID } from '../../../misc/cafy-id';
import define from '../define';
+import { makePaginationQuery } from '../common/make-pagination-query';
+import { Notes } from '../../../models';
export const meta = {
desc: {
@@ -39,14 +40,6 @@ export const meta = {
}
},
- media: {
- validator: $.optional.bool,
- deprecated: true,
- desc: {
- 'ja-JP': 'ファイルが添付された投稿に限定するか否か (このパラメータは廃止予定です。代わりに withFiles を使ってください。)'
- }
- },
-
poll: {
validator: $.optional.bool,
desc: {
@@ -61,12 +54,10 @@ export const meta = {
sinceId: {
validator: $.optional.type(ID),
- transform: transform,
},
untilId: {
validator: $.optional.type(ID),
- transform: transform,
},
},
@@ -79,43 +70,29 @@ export const meta = {
};
export default define(meta, async (ps) => {
- const sort = {
- _id: -1
- };
- const query = {
- deletedAt: null,
- visibility: 'public',
- localOnly: { $ne: true },
- } as any;
- if (ps.sinceId) {
- sort._id = 1;
- query._id = {
- $gt: ps.sinceId
- };
- } else if (ps.untilId) {
- query._id = {
- $lt: ps.untilId
- };
- }
+ const query = makePaginationQuery(Notes.createQueryBuilder('note'), ps.sinceId, ps.untilId)
+ .andWhere(`note.visibility = 'public'`)
+ .andWhere(`note.localOnly = FALSE`)
+ .leftJoinAndSelect('note.user', 'user');
if (ps.local) {
- query['_user.host'] = null;
+ query.andWhere('note.userHost IS NULL');
}
if (ps.reply != undefined) {
- query.replyId = ps.reply ? { $exists: true, $ne: null } : null;
+ query.andWhere(ps.reply ? 'note.replyId IS NOT NULL' : 'note.replyId IS NULL');
}
if (ps.renote != undefined) {
- query.renoteId = ps.renote ? { $exists: true, $ne: null } : null;
+ query.andWhere(ps.renote ? 'note.renoteId IS NOT NULL' : 'note.renoteId IS NULL');
}
- const withFiles = ps.withFiles != undefined ? ps.withFiles : ps.media;
-
- if (withFiles) query.fileIds = { $exists: true, $ne: null };
+ if (ps.withFiles != undefined) {
+ query.andWhere(ps.withFiles ? `note.fileIds != '{}'` : `note.fileIds = '{}'`);
+ }
if (ps.poll != undefined) {
- query.poll = ps.poll ? { $exists: true, $ne: null } : null;
+ query.andWhere(ps.poll ? 'note.hasPoll = TRUE' : 'note.hasPoll = FALSE');
}
// TODO
@@ -123,10 +100,7 @@ export default define(meta, async (ps) => {
// query.isBot = bot;
//}
- const notes = await Note.find(query, {
- limit: ps.limit,
- sort: sort
- });
+ const notes = await query.take(ps.limit).getMany();
- return await packMany(notes);
+ return await Notes.packMany(notes);
});