This commit is contained in:
syuilo 2020-03-23 19:47:02 +09:00
parent 833c39969b
commit a43a225740
1 changed files with 9 additions and 2 deletions

View File

@ -102,6 +102,13 @@ export const meta = {
}; };
export default define(meta, async (ps, user) => { export default define(meta, async (ps, user) => {
const hasFollowing = (await Followings.count({
where: {
followerId: user.id,
},
take: 1
})) !== 0;
//#region Construct query //#region Construct query
const followingQuery = Followings.createQueryBuilder('following') const followingQuery = Followings.createQueryBuilder('following')
.select('following.followeeId') .select('following.followeeId')
@ -110,8 +117,8 @@ export default define(meta, async (ps, user) => {
const query = makePaginationQuery(Notes.createQueryBuilder('note'), const query = makePaginationQuery(Notes.createQueryBuilder('note'),
ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate) ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate)
.andWhere(new Brackets(qb => { qb .andWhere(new Brackets(qb => { qb
.where(`note.userId IN (${ followingQuery.getQuery() })`) .where('note.userId = :meId', { meId: user.id });
.orWhere('note.userId = :meId', { meId: user.id }); if (hasFollowing) qb.orWhere(`note.userId IN (${ followingQuery.getQuery() })`);
})) }))
.leftJoinAndSelect('note.user', 'user') .leftJoinAndSelect('note.user', 'user')
.setParameters(followingQuery.getParameters()); .setParameters(followingQuery.getParameters());