2023-07-27 07:31:52 +02:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-09-17 20:27:08 +02:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
2023-02-16 15:09:41 +01:00
|
|
|
import { In } from 'typeorm';
|
2022-09-17 20:27:08 +02:00
|
|
|
import { DI } from '@/di-symbols.js';
|
2023-09-15 07:28:29 +02:00
|
|
|
import type { MutingsRepository } from '@/models/_.js';
|
2022-09-17 20:27:08 +02:00
|
|
|
import type Logger from '@/logger.js';
|
2023-04-05 03:21:10 +02:00
|
|
|
import { bindThis } from '@/decorators.js';
|
|
|
|
import { UserMutingService } from '@/core/UserMutingService.js';
|
2022-09-17 20:27:08 +02:00
|
|
|
import { QueueLoggerService } from '../QueueLoggerService.js';
|
2023-05-29 04:54:49 +02:00
|
|
|
import type * as Bull from 'bullmq';
|
2022-09-17 20:27:08 +02:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class CheckExpiredMutingsProcessorService {
|
2022-09-18 20:11:50 +02:00
|
|
|
private logger: Logger;
|
2022-09-17 20:27:08 +02:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.mutingsRepository)
|
|
|
|
private mutingsRepository: MutingsRepository,
|
|
|
|
|
2023-04-05 03:21:10 +02:00
|
|
|
private userMutingService: UserMutingService,
|
2022-09-17 20:27:08 +02:00
|
|
|
private queueLoggerService: QueueLoggerService,
|
|
|
|
) {
|
2022-09-18 20:11:50 +02:00
|
|
|
this.logger = this.queueLoggerService.logger.createSubLogger('check-expired-mutings');
|
2022-09-17 20:27:08 +02:00
|
|
|
}
|
|
|
|
|
2022-12-04 07:03:09 +01:00
|
|
|
@bindThis
|
2023-05-29 04:54:49 +02:00
|
|
|
public async process(): Promise<void> {
|
2022-09-18 20:11:50 +02:00
|
|
|
this.logger.info('Checking expired mutings...');
|
2022-09-17 20:27:08 +02:00
|
|
|
|
|
|
|
const expired = await this.mutingsRepository.createQueryBuilder('muting')
|
|
|
|
.where('muting.expiresAt IS NOT NULL')
|
|
|
|
.andWhere('muting.expiresAt < :now', { now: new Date() })
|
|
|
|
.innerJoinAndSelect('muting.mutee', 'mutee')
|
|
|
|
.getMany();
|
|
|
|
|
|
|
|
if (expired.length > 0) {
|
2023-04-05 03:21:10 +02:00
|
|
|
await this.userMutingService.unmute(expired);
|
2022-09-17 20:27:08 +02:00
|
|
|
}
|
|
|
|
|
2022-09-18 20:11:50 +02:00
|
|
|
this.logger.succ('All expired mutings checked.');
|
2022-09-17 20:27:08 +02:00
|
|
|
}
|
|
|
|
}
|