2019-02-05 02:48:08 +00:00
|
|
|
import $ from 'cafy';
|
2019-04-07 12:50:36 +00:00
|
|
|
import { ID } from '../../../../misc/cafy-id';
|
2018-11-02 04:47:44 +00:00
|
|
|
import define from '../../define';
|
2019-04-07 12:50:36 +00:00
|
|
|
import { makePaginationQuery } from '../../common/make-pagination-query';
|
|
|
|
import { Notes } from '../../../../models';
|
2020-07-28 00:38:41 +00:00
|
|
|
import { generateMutedUserQuery } from '../../common/generate-muted-user-query';
|
2019-04-07 12:50:36 +00:00
|
|
|
import { generateVisibilityQuery } from '../../common/generate-visibility-query';
|
|
|
|
import { Brackets } from 'typeorm';
|
2020-02-19 22:18:40 +00:00
|
|
|
import { safeForSql } from '../../../../misc/safe-for-sql';
|
2021-02-07 01:43:34 +00:00
|
|
|
import { normalizeForSearch } from '../../../../misc/normalize-for-search';
|
2018-06-10 03:19:19 +00:00
|
|
|
|
2018-09-05 14:55:51 +00:00
|
|
|
export const meta = {
|
|
|
|
desc: {
|
|
|
|
'ja-JP': '指定されたタグが付けられた投稿を取得します。'
|
|
|
|
},
|
|
|
|
|
2019-02-23 02:20:58 +00:00
|
|
|
tags: ['notes', 'hashtags'],
|
|
|
|
|
2018-09-05 14:55:51 +00:00
|
|
|
params: {
|
2018-11-01 18:32:24 +00:00
|
|
|
tag: {
|
2019-02-13 07:33:07 +00:00
|
|
|
validator: $.optional.str,
|
2018-09-05 14:55:51 +00:00
|
|
|
desc: {
|
|
|
|
'ja-JP': 'タグ'
|
|
|
|
}
|
2018-11-01 18:32:24 +00:00
|
|
|
},
|
2018-09-05 14:55:51 +00:00
|
|
|
|
2018-11-01 18:32:24 +00:00
|
|
|
query: {
|
2019-02-13 07:33:07 +00:00
|
|
|
validator: $.optional.arr($.arr($.str)),
|
2018-09-17 00:00:20 +00:00
|
|
|
desc: {
|
|
|
|
'ja-JP': 'クエリ'
|
|
|
|
}
|
2018-11-01 18:32:24 +00:00
|
|
|
},
|
2018-09-17 00:00:20 +00:00
|
|
|
|
2018-11-01 18:32:24 +00:00
|
|
|
reply: {
|
2019-02-13 07:33:07 +00:00
|
|
|
validator: $.optional.nullable.bool,
|
2018-11-01 18:32:24 +00:00
|
|
|
default: null as any,
|
2018-09-05 14:55:51 +00:00
|
|
|
desc: {
|
|
|
|
'ja-JP': '返信に限定するか否か'
|
|
|
|
}
|
2018-11-01 18:32:24 +00:00
|
|
|
},
|
2018-06-10 03:19:19 +00:00
|
|
|
|
2018-11-01 18:32:24 +00:00
|
|
|
renote: {
|
2019-02-13 07:33:07 +00:00
|
|
|
validator: $.optional.nullable.bool,
|
2018-11-01 18:32:24 +00:00
|
|
|
default: null as any,
|
2018-09-05 14:55:51 +00:00
|
|
|
desc: {
|
|
|
|
'ja-JP': 'Renoteに限定するか否か'
|
|
|
|
}
|
2018-11-01 18:32:24 +00:00
|
|
|
},
|
2018-06-10 03:19:19 +00:00
|
|
|
|
2018-11-01 18:32:24 +00:00
|
|
|
withFiles: {
|
2019-02-13 07:33:07 +00:00
|
|
|
validator: $.optional.bool,
|
2018-09-05 14:55:51 +00:00
|
|
|
desc: {
|
2018-09-17 00:00:20 +00:00
|
|
|
'ja-JP': 'true にすると、ファイルが添付された投稿だけ取得します'
|
2018-09-05 14:55:51 +00:00
|
|
|
}
|
2018-11-01 18:32:24 +00:00
|
|
|
},
|
2018-06-10 03:19:19 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
poll: {
|
2019-02-13 07:33:07 +00:00
|
|
|
validator: $.optional.nullable.bool,
|
2018-11-01 18:32:24 +00:00
|
|
|
default: null as any,
|
2018-09-05 14:55:51 +00:00
|
|
|
desc: {
|
2019-04-07 12:50:36 +00:00
|
|
|
'ja-JP': 'アンケートが添付された投稿に限定するか否か'
|
2018-09-05 14:55:51 +00:00
|
|
|
}
|
2018-11-01 18:32:24 +00:00
|
|
|
},
|
2018-06-10 03:19:19 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
sinceId: {
|
|
|
|
validator: $.optional.type(ID),
|
2018-09-05 14:55:51 +00:00
|
|
|
desc: {
|
2019-04-07 12:50:36 +00:00
|
|
|
'ja-JP': '指定すると、その投稿を基点としてより新しい投稿を取得します'
|
2018-09-05 14:55:51 +00:00
|
|
|
}
|
2018-11-01 18:32:24 +00:00
|
|
|
},
|
2018-06-10 03:19:19 +00:00
|
|
|
|
2018-11-01 18:32:24 +00:00
|
|
|
untilId: {
|
2019-02-13 07:33:07 +00:00
|
|
|
validator: $.optional.type(ID),
|
2018-09-17 02:43:53 +00:00
|
|
|
desc: {
|
2019-04-07 12:50:36 +00:00
|
|
|
'ja-JP': '指定すると、その投稿を基点としてより古い投稿を取得します'
|
2018-09-17 02:43:53 +00:00
|
|
|
}
|
2018-11-01 18:32:24 +00:00
|
|
|
},
|
2018-09-17 02:43:53 +00:00
|
|
|
|
2018-11-01 18:32:24 +00:00
|
|
|
limit: {
|
2020-02-20 13:54:26 +00:00
|
|
|
validator: $.optional.num.range(1, 100),
|
2018-09-05 14:55:51 +00:00
|
|
|
default: 10
|
2018-11-01 18:32:24 +00:00
|
|
|
},
|
2019-02-23 02:20:58 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
2019-06-27 09:04:09 +00:00
|
|
|
type: 'array' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
2019-02-23 02:20:58 +00:00
|
|
|
items: {
|
2019-06-27 09:04:09 +00:00
|
|
|
type: 'object' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
2019-04-23 13:35:26 +00:00
|
|
|
ref: 'Note',
|
|
|
|
}
|
2019-02-23 02:20:58 +00:00
|
|
|
},
|
2018-09-05 14:55:51 +00:00
|
|
|
};
|
|
|
|
|
2019-02-22 02:46:58 +00:00
|
|
|
export default define(meta, async (ps, me) => {
|
2019-04-07 12:50:36 +00:00
|
|
|
const query = makePaginationQuery(Notes.createQueryBuilder('note'), ps.sinceId, ps.untilId)
|
2021-03-21 03:33:37 +00:00
|
|
|
.innerJoinAndSelect('note.user', 'user')
|
2021-03-21 03:31:56 +00:00
|
|
|
.leftJoinAndSelect('note.reply', 'reply')
|
|
|
|
.leftJoinAndSelect('note.renote', 'renote')
|
|
|
|
.leftJoinAndSelect('reply.user', 'replyUser')
|
|
|
|
.leftJoinAndSelect('renote.user', 'renoteUser');
|
2019-04-07 12:50:36 +00:00
|
|
|
|
2019-12-11 15:49:30 +00:00
|
|
|
generateVisibilityQuery(query, me);
|
2020-07-28 00:38:41 +00:00
|
|
|
if (me) generateMutedUserQuery(query, me);
|
2019-04-07 12:50:36 +00:00
|
|
|
|
|
|
|
if (ps.tag) {
|
2020-02-19 22:18:40 +00:00
|
|
|
if (!safeForSql(ps.tag)) return;
|
2021-02-07 01:43:34 +00:00
|
|
|
query.andWhere(`'{"${normalizeForSearch(ps.tag)}"}' <@ note.tags`);
|
2019-04-07 12:50:36 +00:00
|
|
|
} else {
|
|
|
|
let i = 0;
|
|
|
|
query.andWhere(new Brackets(qb => {
|
2019-04-12 16:43:22 +00:00
|
|
|
for (const tags of ps.query!) {
|
2019-04-07 12:50:36 +00:00
|
|
|
qb.orWhere(new Brackets(qb => {
|
|
|
|
for (const tag of tags) {
|
2020-02-19 22:18:40 +00:00
|
|
|
if (!safeForSql(tag)) return;
|
2021-02-07 01:43:34 +00:00
|
|
|
qb.andWhere(`'{"${normalizeForSearch(ps.tag)}"}' <@ note.tags`);
|
2019-04-07 12:50:36 +00:00
|
|
|
i++;
|
2018-06-10 03:19:19 +00:00
|
|
|
}
|
2019-04-07 12:50:36 +00:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
}));
|
2018-06-10 03:19:19 +00:00
|
|
|
}
|
|
|
|
|
2018-09-05 14:55:51 +00:00
|
|
|
if (ps.reply != null) {
|
|
|
|
if (ps.reply) {
|
2019-04-07 12:50:36 +00:00
|
|
|
query.andWhere('note.replyId IS NOT NULL');
|
2018-06-10 03:19:19 +00:00
|
|
|
} else {
|
2019-04-07 12:50:36 +00:00
|
|
|
query.andWhere('note.replyId IS NULL');
|
2018-06-10 03:19:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-05 14:55:51 +00:00
|
|
|
if (ps.renote != null) {
|
|
|
|
if (ps.renote) {
|
2019-04-07 12:50:36 +00:00
|
|
|
query.andWhere('note.renoteId IS NOT NULL');
|
2018-06-10 03:19:19 +00:00
|
|
|
} else {
|
2019-04-07 12:50:36 +00:00
|
|
|
query.andWhere('note.renoteId IS NULL');
|
2018-06-10 03:19:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
if (ps.withFiles) {
|
|
|
|
query.andWhere('note.fileIds != \'{}\'');
|
2018-06-10 03:19:19 +00:00
|
|
|
}
|
|
|
|
|
2018-09-05 14:55:51 +00:00
|
|
|
if (ps.poll != null) {
|
|
|
|
if (ps.poll) {
|
2019-04-07 12:50:36 +00:00
|
|
|
query.andWhere('note.hasPoll = TRUE');
|
2018-06-10 03:19:19 +00:00
|
|
|
} else {
|
2019-04-07 12:50:36 +00:00
|
|
|
query.andWhere('note.hasPoll = FALSE');
|
2018-06-10 03:19:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Search notes
|
2020-02-19 22:19:27 +00:00
|
|
|
const notes = await query.take(ps.limit!).getMany();
|
2018-06-10 03:19:19 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
return await Notes.packMany(notes, me);
|
2019-02-22 02:46:58 +00:00
|
|
|
});
|