2021-08-19 07:55:45 -05:00
|
|
|
import { User } from '@/models/entities/user';
|
2020-02-15 06:39:38 -06:00
|
|
|
import { Brackets, SelectQueryBuilder } from 'typeorm';
|
|
|
|
|
2022-02-06 01:02:48 -06:00
|
|
|
export function generateRepliesQuery(q: SelectQueryBuilder<any>, me?: Pick<User, 'id' | 'showTimelineReplies'> | null) {
|
2020-02-15 06:39:38 -06:00
|
|
|
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');
|
|
|
|
}));
|
|
|
|
}));
|
2022-02-15 08:08:50 -06:00
|
|
|
} else if (!me.showTimelineReplies) {
|
2020-02-15 06:39:38 -06:00
|
|
|
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');
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|