This commit is contained in:
ThatOneCalculator 2022-11-06 14:20:14 -08:00
parent 9ea3af662d
commit 9b3e578c9e

View file

@ -1,7 +1,7 @@
import define from '../../define.js';
import { MessagingMessage } from '@/models/entities/messaging-message.js';
import { MessagingMessages, Mutings, UserGroupJoinings } from '@/models/index.js';
import { Brackets } from 'typeorm';
import type { MessagingMessage } from '@/models/entities/messaging-message.js';
import { MessagingMessages, Mutings, UserGroupJoinings } from '@/models/index.js';
import define from '../../define.js';
export const meta = {
tags: ['messaging'],
@ -55,26 +55,26 @@ export default define(meta, paramDef, async (ps, user) => {
.orderBy('message.createdAt', 'DESC');
if (ps.group) {
query.where(`message.groupId IN (:...groups)`, { groups: groups });
query.where('message.groupId IN (:...groups)', { groups: groups });
if (found.length > 0) {
query.andWhere(`message.groupId NOT IN (:...found)`, { found: found });
query.andWhere('message.groupId NOT IN (:...found)', { found: found });
}
} else {
query.where(new Brackets(qb => { qb
.where(`message.userId = :userId`, { userId: user.id })
.orWhere(`message.recipientId = :userId`, { userId: user.id });
.where('message.userId = :userId', { userId: user.id })
.orWhere('message.recipientId = :userId', { userId: user.id });
}));
query.andWhere(`message.groupId IS NULL`);
query.andWhere('message.groupId IS NULL');
if (found.length > 0) {
query.andWhere(`message.userId NOT IN (:...found)`, { found: found });
query.andWhere(`message.recipientId NOT IN (:...found)`, { found: found });
query.andWhere('message.userId NOT IN (:...found)', { found: found });
query.andWhere('message.recipientId NOT IN (:...found)', { found: found });
}
if (mute.length > 0) {
query.andWhere(`message.userId NOT IN (:...mute)`, { mute: mute.map(m => m.muteeId) });
query.andWhere(`message.recipientId NOT IN (:...mute)`, { mute: mute.map(m => m.muteeId) });
query.andWhere('message.userId NOT IN (:...mute)', { mute: mute.map(m => m.muteeId) });
query.andWhere('message.recipientId NOT IN (:...mute)', { mute: mute.map(m => m.muteeId) });
}
}