FoundKey-0x7f/packages/backend/src/queue/processors/system/check-expired-mutings.ts
Johann150 37e47a257e
fix lints "import/order" and "import/no-duplicate"
Also simplified some import paths by replacing relative with absolute paths.
2022-08-03 14:05:50 +02:00

31 lines
894 B
TypeScript

import Bull from 'bull';
import { In } from 'typeorm';
import { Mutings } from '@/models/index.js';
import { publishUserEvent } from '@/services/stream.js';
import { queueLogger } from '../../logger.js';
const logger = queueLogger.createSubLogger('check-expired-mutings');
export async function checkExpiredMutings(job: Bull.Job<Record<string, unknown>>, done: any): Promise<void> {
logger.info('Checking expired mutings...');
const expired = await Mutings.createQueryBuilder('muting')
.where('muting.expiresAt IS NOT NULL')
.andWhere('muting.expiresAt < :now', { now: new Date() })
.innerJoinAndSelect('muting.mutee', 'mutee')
.getMany();
if (expired.length > 0) {
await Mutings.delete({
id: In(expired.map(m => m.id)),
});
for (const m of expired) {
publishUserEvent(m.muterId, 'unmute', m.mutee!);
}
}
logger.succ('All expired mutings checked.');
done();
}