summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/UserRenoteMutingService.ts
diff options
context:
space:
mode:
authorかっこかり <67428053+kakkokari-gtyih@users.noreply.github.com>2024-07-18 08:55:36 +0900
committerGitHub <noreply@github.com>2024-07-18 08:55:36 +0900
commitde166a8ed4b0e185e49c71825c92b4f94e2f350f (patch)
tree1f4ecd6b965676a81df4edd9d31b76abc6dfac40 /packages/backend/src/core/UserRenoteMutingService.ts
parentchore: CHANGELOGにジョブキュー設定について追記 (follow-up of #... (diff)
downloadsharkey-de166a8ed4b0e185e49c71825c92b4f94e2f350f.tar.gz
sharkey-de166a8ed4b0e185e49c71825c92b4f94e2f350f.tar.bz2
sharkey-de166a8ed4b0e185e49c71825c92b4f94e2f350f.zip
fix(backend): リノートミュートがキャッシュが切れるまで効かない問題を修正 (#14242)
* Fix: RenoteMuteがキャッシュが切れるまで効かない問題を修正 (cherry picked from commit e9601029b52e0ad43d9131b555b614e56c84ebc1) * update changelog * :art: * remove unused import * 消したときもキャッシュを飛ばすように * lint --------- Co-authored-by: mattyatea <mattyacocacora0@gmail.com>
Diffstat (limited to 'packages/backend/src/core/UserRenoteMutingService.ts')
-rw-r--r--packages/backend/src/core/UserRenoteMutingService.ts52
1 files changed, 52 insertions, 0 deletions
diff --git a/packages/backend/src/core/UserRenoteMutingService.ts b/packages/backend/src/core/UserRenoteMutingService.ts
new file mode 100644
index 0000000000..bdc5e23f4b
--- /dev/null
+++ b/packages/backend/src/core/UserRenoteMutingService.ts
@@ -0,0 +1,52 @@
+/*
+ * SPDX-FileCopyrightText: syuilo and misskey-project , Type4ny-project
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+import { Inject, Injectable } from '@nestjs/common';
+import { In } from 'typeorm';
+import type { RenoteMutingsRepository } from '@/models/_.js';
+import type { MiRenoteMuting } from '@/models/RenoteMuting.js';
+
+import { IdService } from '@/core/IdService.js';
+import type { MiUser } from '@/models/User.js';
+import { DI } from '@/di-symbols.js';
+import { bindThis } from '@/decorators.js';
+import { CacheService } from '@/core/CacheService.js';
+
+@Injectable()
+export class UserRenoteMutingService {
+ constructor(
+ @Inject(DI.renoteMutingsRepository)
+ private renoteMutingsRepository: RenoteMutingsRepository,
+
+ private idService: IdService,
+ private cacheService: CacheService,
+ ) {
+ }
+
+ @bindThis
+ public async mute(user: MiUser, target: MiUser, expiresAt: Date | null = null): Promise<void> {
+ await this.renoteMutingsRepository.insert({
+ id: this.idService.gen(),
+ muterId: user.id,
+ muteeId: target.id,
+ });
+
+ await this.cacheService.renoteMutingsCache.refresh(user.id);
+ }
+
+ @bindThis
+ public async unmute(mutings: MiRenoteMuting[]): Promise<void> {
+ if (mutings.length === 0) return;
+
+ await this.renoteMutingsRepository.delete({
+ id: In(mutings.map(m => m.id)),
+ });
+
+ const muterIds = [...new Set(mutings.map(m => m.muterId))];
+ for (const muterId of muterIds) {
+ await this.cacheService.renoteMutingsCache.refresh(muterId);
+ }
+ }
+}