-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: 特定ユーザーからのリアクションをブロックする機能の追加 #14992
Open
sakuhanight
wants to merge
21
commits into
misskey-dev:develop
Choose a base branch
from
sakuhanight:misskey-dev/blocking-reaction-user
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+958
−16
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
3dd5af3
Add: BlockingテーブルにisReactionBlockカラムを追加し、blocking-reaction-userエンドポイン…
sakuhanight 37627bb
Add: リアクションブロックの設定画面を追加
sakuhanight 51a2a7d
Add: フロントエンドのユーザーメニューにリアクションブロックを追加
sakuhanight 1b0ac28
fix
sakuhanight 9ef2dbb
Mod: ログ出力を英語に変更
sakuhanight 202fcee
fix: as -> satisfies
sakuhanight 3ea69b6
Mod: isReactionBlockからenumに変更
sakuhanight 24792e0
Add: リアクションのブロック判定にblockingReactionUserService.checkBlockedを追加
sakuhanight 2665294
fix: code styleの修正
sakuhanight 0301e86
Mod: Migrationファイルを再作成
sakuhanight da94dbe
Mod: UserReactionBlockingServiceとUserBlockingServiceを統合
sakuhanight 34da11f
fix: import周りの諸々修正
sakuhanight 292809a
fix: SPDXつけ忘れ
sakuhanight a96ae92
fix: ReactionService
sakuhanight ac95b12
Merge branch 'develop' into misskey-dev/blocking-reaction-user
sakuhanight fd9b7ed
fix: クエリとか修正
sakuhanight 6236c93
fix: code style の修正
sakuhanight 65ff7b1
Merge branch 'misskey-dev/develop' into misskey-dev/blocking-reaction…
sakuhanight 8dad086
fix
sakuhanight 314fbc3
fix
sakuhanight 52c18ae
Merge branch 'develop' into misskey-dev/blocking-reaction-user
sakuhanight File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/backend/migration/1731932268436-addBlockingReactionUser.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* SPDX-FileCopyrightText: syuilo and misskey-project | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
export class AddBlockingReactionUser1731932268436 { | ||
name = 'AddBlockingReactionUser1731932268436' | ||
|
||
async up(queryRunner) { | ||
await queryRunner.query(`ALTER TABLE "blocking" ADD "blockType" character varying NOT NULL DEFAULT 'user'`); | ||
await queryRunner.query(`COMMENT ON COLUMN "blocking"."blockType" IS 'Block type.'`); | ||
await queryRunner.query(`CREATE INDEX "IDX_cd38e7ea08163899a2d1f4427d" ON "blocking" ("blockType") `); | ||
} | ||
|
||
async down(queryRunner) { | ||
await queryRunner.query(`DELETE FROM blocking WHERE "blockType" = 'reaction'`); // blockingテーブルのblockTypeがreactionの行を削除 | ||
await queryRunner.query(`DROP INDEX "public"."IDX_cd38e7ea08163899a2d1f4427d"`); | ||
await queryRunner.query(`COMMENT ON COLUMN "blocking"."blockType" IS 'Block type.'`); | ||
await queryRunner.query(`ALTER TABLE "blocking" DROP COLUMN "blockType"`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,16 @@ import { ModuleRef } from '@nestjs/core'; | |
import { IdService } from '@/core/IdService.js'; | ||
import type { MiUser } from '@/models/User.js'; | ||
import type { MiBlocking } from '@/models/Blocking.js'; | ||
import { MiBlockingType } from '@/models/Blocking.js'; | ||
import { QueueService } from '@/core/QueueService.js'; | ||
import { GlobalEventService } from '@/core/GlobalEventService.js'; | ||
import { DI } from '@/di-symbols.js'; | ||
import type { FollowRequestsRepository, BlockingsRepository, UserListsRepository, UserListMembershipsRepository } from '@/models/_.js'; | ||
import type { | ||
BlockingsRepository, | ||
FollowRequestsRepository, | ||
UserListMembershipsRepository, | ||
UserListsRepository, | ||
} from '@/models/_.js'; | ||
import Logger from '@/logger.js'; | ||
import { UserEntityService } from '@/core/entities/UserEntityService.js'; | ||
import { ApRendererService } from '@/core/activitypub/ApRendererService.js'; | ||
|
@@ -67,14 +73,27 @@ export class UserBlockingService implements OnModuleInit { | |
this.removeFromList(blockee, blocker), | ||
]); | ||
|
||
const blocking = { | ||
id: this.idService.gen(), | ||
blocker, | ||
const blocking = await this.blockingsRepository.findOneBy({ | ||
blockerId: blocker.id, | ||
blockee, | ||
blockeeId: blockee.id, | ||
} as MiBlocking; | ||
}).then(blocking => { | ||
if (blocking) { | ||
return blocking; | ||
} | ||
return { | ||
id: this.idService.gen(), | ||
blocker, | ||
blockerId: blocker.id, | ||
blockee, | ||
blockeeId: blockee.id, | ||
blockType: MiBlockingType.User, | ||
} as MiBlocking; | ||
}); | ||
|
||
if (blocking.blockType === MiBlockingType.Reaction) { | ||
await this.reactionUnblock(blocker, blockee); | ||
} | ||
blocking.blockType = MiBlockingType.User; | ||
await this.blockingsRepository.insert(blocking); | ||
|
||
this.cacheService.userBlockingCache.refresh(blocker.id); | ||
|
@@ -160,6 +179,7 @@ export class UserBlockingService implements OnModuleInit { | |
const blocking = await this.blockingsRepository.findOneBy({ | ||
blockerId: blocker.id, | ||
blockeeId: blockee.id, | ||
blockType: MiBlockingType.User, | ||
}); | ||
|
||
if (blocking == null) { | ||
|
@@ -169,6 +189,7 @@ export class UserBlockingService implements OnModuleInit { | |
|
||
// Since we already have the blocker and blockee, we do not need to fetch | ||
// them in the query above and can just manually insert them here. | ||
// But we don't need to do this because we are not using them in this function. | ||
blocking.blocker = blocker; | ||
blocking.blockee = blockee; | ||
|
||
|
@@ -193,4 +214,73 @@ export class UserBlockingService implements OnModuleInit { | |
public async checkBlocked(blockerId: MiUser['id'], blockeeId: MiUser['id']): Promise<boolean> { | ||
return (await this.cacheService.userBlockingCache.fetch(blockerId)).has(blockeeId); | ||
} | ||
|
||
@bindThis | ||
public async reactionBlock(blocker: MiUser, blockee: MiUser, silent = false) { | ||
const blocking = await this.blockingsRepository.findOneBy({ | ||
blockerId: blocker.id, | ||
blockeeId: blockee.id, | ||
}).then(blocking => { | ||
if (blocking) { | ||
return blocking; | ||
} | ||
return { | ||
id: this.idService.gen(), | ||
blocker, | ||
blockerId: blocker.id, | ||
blockee, | ||
blockeeId: blockee.id, | ||
blockType: MiBlockingType.Reaction, | ||
} as MiBlocking; | ||
}); | ||
|
||
if (blocking.blockType === MiBlockingType.User) { | ||
await this.unblock(blocker, blockee); | ||
} | ||
blocking.blockType = MiBlockingType.Reaction; | ||
await this.blockingsRepository.insert(blocking); | ||
|
||
this.cacheService.userReactionBlockingCache.refresh(blocker.id); | ||
this.cacheService.userReactionBlockedCache.refresh(blockee.id); | ||
|
||
this.globalEventService.publishInternalEvent('blockingReactionCreated', { | ||
blockerId: blocker.id, | ||
blockeeId: blockee.id, | ||
}); | ||
} | ||
|
||
@bindThis | ||
public async reactionUnblock(blocker: MiUser, blockee: MiUser) { | ||
const blocking = await this.blockingsRepository.findOneBy({ | ||
blockerId: blocker.id, | ||
blockeeId: blockee.id, | ||
blockType: MiBlockingType.Reaction, | ||
}); | ||
|
||
if (blocking == null) { | ||
this.logger.warn('Unblock requested, but the target was not blocked.'); | ||
return; | ||
} | ||
|
||
// Since we already have the blocker and blockee, we do not need to fetch | ||
// them in the query above and can just manually insert them here. | ||
blocking.blocker = blocker; | ||
blocking.blockee = blockee; | ||
|
||
await this.blockingsRepository.delete(blocking.id); | ||
|
||
this.cacheService.userReactionBlockingCache.refresh(blocker.id); | ||
this.cacheService.userReactionBlockedCache.refresh(blockee.id); | ||
|
||
this.globalEventService.publishInternalEvent('blockingReactionDeleted', { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. こちらも、配信するイベントが変わっています |
||
blockerId: blocker.id, | ||
blockeeId: blockee.id, | ||
}); | ||
} | ||
|
||
@bindThis | ||
public async checkReactionBlocked(blockerId: MiUser['id'], blockeeId: MiUser['id']): Promise<boolean> { | ||
return (await this.cacheService.userReactionBlockingCache.fetch(blockerId)).has(blockeeId); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
このServiceは通常のブロック向けかと思いますが、ここでリアクションブロック向けの機能を更新しているのは特殊な理由がありますか…?