diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2020-02-15 21:39:38 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2020-02-15 21:39:38 +0900 |
| commit | d0085f00edac5971a36ad9258c1ece9fb129fbeb (patch) | |
| tree | c70705ab63feb430638802def926cb047a5b6ffb /src/server/api/common | |
| parent | Refactoring (diff) | |
| download | sharkey-d0085f00edac5971a36ad9258c1ece9fb129fbeb.tar.gz sharkey-d0085f00edac5971a36ad9258c1ece9fb129fbeb.tar.bz2 sharkey-d0085f00edac5971a36ad9258c1ece9fb129fbeb.zip | |
Fix #5950
Diffstat (limited to 'src/server/api/common')
| -rw-r--r-- | src/server/api/common/generate-replies-query.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/server/api/common/generate-replies-query.ts b/src/server/api/common/generate-replies-query.ts new file mode 100644 index 0000000000..c7ca742e2f --- /dev/null +++ b/src/server/api/common/generate-replies-query.ts @@ -0,0 +1,27 @@ +import { User } from '../../../models/entities/user'; +import { Brackets, SelectQueryBuilder } from 'typeorm'; + +export function generateRepliesQuery(q: SelectQueryBuilder<any>, me?: User) { + if (me == null) { + q.andWhere(new Brackets(qb => { qb + .where(`note.replyId IS NULL`) // 返信ではない + .orWhere(new Brackets(qb => { qb // 返信だけど投稿者自身への返信 + .where(`note.replyId IS NOT NULL`) + .andWhere('note.replyUserId = note.userId'); + })); + })); + } else { + q.andWhere(new Brackets(qb => { qb + .where(`note.replyId IS NULL`) // 返信ではない + .orWhere('note.replyUserId = :meId', { meId: me.id }) // 返信だけど自分のノートへの返信 + .orWhere(new Brackets(qb => { qb // 返信だけど自分の行った返信 + .where(`note.replyId IS NOT NULL`) + .andWhere('note.userId = :meId', { meId: me.id }); + })) + .orWhere(new Brackets(qb => { qb // 返信だけど投稿者自身への返信 + .where(`note.replyId IS NOT NULL`) + .andWhere('note.replyUserId = note.userId'); + })); + })); + } +} |