2023-07-27 00:31:52 -05:00
|
|
|
/*
|
2024-02-13 09:59:27 -06:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 00:31:52 -05:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-09-17 13:27:08 -05:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
2023-04-04 20:21:10 -05:00
|
|
|
import { In } from 'typeorm';
|
2023-09-15 00:28:29 -05:00
|
|
|
import type { MutingsRepository, MiMuting } from '@/models/_.js';
|
2022-09-17 13:27:08 -05:00
|
|
|
import { IdService } from '@/core/IdService.js';
|
2023-09-19 21:33:36 -05:00
|
|
|
import type { MiUser } from '@/models/User.js';
|
2022-09-17 13:27:08 -05:00
|
|
|
import { DI } from '@/di-symbols.js';
|
2022-12-04 00:03:09 -06:00
|
|
|
import { bindThis } from '@/decorators.js';
|
2023-04-04 23:50:05 -05:00
|
|
|
import { CacheService } from '@/core/CacheService.js';
|
2022-09-17 13:27:08 -05:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class UserMutingService {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.mutingsRepository)
|
|
|
|
private mutingsRepository: MutingsRepository,
|
|
|
|
|
|
|
|
private idService: IdService,
|
2023-04-04 20:21:10 -05:00
|
|
|
private cacheService: CacheService,
|
2022-09-17 13:27:08 -05:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2022-12-04 00:03:09 -06:00
|
|
|
@bindThis
|
2023-08-16 03:51:28 -05:00
|
|
|
public async mute(user: MiUser, target: MiUser, expiresAt: Date | null = null): Promise<void> {
|
2022-09-17 13:27:08 -05:00
|
|
|
await this.mutingsRepository.insert({
|
2023-10-15 20:45:22 -05:00
|
|
|
id: this.idService.gen(),
|
2023-04-04 20:21:10 -05:00
|
|
|
expiresAt: expiresAt ?? null,
|
2022-09-17 13:27:08 -05:00
|
|
|
muterId: user.id,
|
|
|
|
muteeId: target.id,
|
|
|
|
});
|
2023-04-04 20:21:10 -05:00
|
|
|
|
|
|
|
this.cacheService.userMutingsCache.refresh(user.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
@bindThis
|
2023-08-16 03:51:28 -05:00
|
|
|
public async unmute(mutings: MiMuting[]): Promise<void> {
|
2023-04-04 20:21:10 -05:00
|
|
|
if (mutings.length === 0) return;
|
|
|
|
|
|
|
|
await this.mutingsRepository.delete({
|
|
|
|
id: In(mutings.map(m => m.id)),
|
|
|
|
});
|
|
|
|
|
|
|
|
const muterIds = [...new Set(mutings.map(m => m.muterId))];
|
|
|
|
for (const muterId of muterIds) {
|
|
|
|
this.cacheService.userMutingsCache.refresh(muterId);
|
|
|
|
}
|
2022-09-17 13:27:08 -05:00
|
|
|
}
|
|
|
|
}
|