mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-15 12:53:08 +02:00
792622aead
* wip * wip * wip * wip * Update RepositoryModule.ts * wip * wip * wip * Revert "wip" This reverts commit c1c13b37d2aaf3c65bc148212da302b0eb7868bf.
52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
import { In } from 'typeorm';
|
|
import type { MutingsRepository, MiMuting } from '@/models/index.js';
|
|
import { IdService } from '@/core/IdService.js';
|
|
import type { MiUser } from '@/models/entities/User.js';
|
|
import { DI } from '@/di-symbols.js';
|
|
import { bindThis } from '@/decorators.js';
|
|
import { CacheService } from '@/core/CacheService.js';
|
|
|
|
@Injectable()
|
|
export class UserMutingService {
|
|
constructor(
|
|
@Inject(DI.mutingsRepository)
|
|
private mutingsRepository: MutingsRepository,
|
|
|
|
private idService: IdService,
|
|
private cacheService: CacheService,
|
|
) {
|
|
}
|
|
|
|
@bindThis
|
|
public async mute(user: MiUser, target: MiUser, expiresAt: Date | null = null): Promise<void> {
|
|
await this.mutingsRepository.insert({
|
|
id: this.idService.genId(),
|
|
createdAt: new Date(),
|
|
expiresAt: expiresAt ?? null,
|
|
muterId: user.id,
|
|
muteeId: target.id,
|
|
});
|
|
|
|
this.cacheService.userMutingsCache.refresh(user.id);
|
|
}
|
|
|
|
@bindThis
|
|
public async unmute(mutings: MiMuting[]): Promise<void> {
|
|
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);
|
|
}
|
|
}
|
|
}
|