forked from misskey-dev/misskey
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- BlockingReactionUserエンティティの追加 - blocking-reaction-userエンドポイントの追加 - 関連するフロントエンドの追加 Migrationがあります。
- Loading branch information
1 parent
413a2e9
commit a8f0627
Showing
29 changed files
with
798 additions
and
7 deletions.
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
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
34 changes: 34 additions & 0 deletions
34
packages/backend/migration/1731566099974-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,34 @@ | ||
/* | ||
* SPDX-FileCopyrightText: sakuhanight and misskey-project | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
export class MakeNotesHiddenBefore1729486255072 { | ||
name = 'AddBlockingReactionUser1731566099974' | ||
async up(queryRunner) { | ||
await queryRunner.query(` | ||
CREATE TABLE "blocking_reaction_user"( | ||
id varchar(32) NULL, | ||
blockeeId varchar(32) NULL, | ||
blockerId varchar(32) NULL, | ||
CONSTRAINT "PK_blocking_reaction_user" PRIMARY KEY (id), | ||
CONSTRAINT "FK_blocking_reaction_user_blockeeid" FOREIGN KEY (blockeeid) REFERENCES "user" (id) ON DELETE CASCADE, | ||
CONSTRAINT "FK_blocking_reaction_user_blockerid" FOREIGN KEY (blockerid) REFERENCES "user" (id) ON DELETE CASCADE); | ||
`); | ||
await queryRunner.query(`CREATE INDEX "IDX_blocking_reaction_user_id" ON "blocking_reaction_user" (id);`); | ||
await queryRunner.query(`CREATE INDEX "IDX_blocking_reaction_user_blockeeid" ON "blocking_reaction_user" (blockeeid);`); | ||
await queryRunner.query(`CREATE INDEX "IDX_blocking_reaction_user_blockerid" ON "blocking_reaction_user" (blockerid);`); | ||
await queryRunner.query(`CREATE UNIQUE INDEX "IDX_blocking_reaction_user_blockeeid_blockerid" ON "blocking_reaction_user" (blockeeid, blockerid);`); | ||
} | ||
|
||
async down(queryRunner) { | ||
await queryRunner.query(`DROP INDEX "IDX_blocking_reaction_user_blockeeid_blockerid";`); | ||
await queryRunner.query(`DROP INDEX "IDX_blocking_reaction_user_blockerid";`); | ||
await queryRunner.query(`DROP INDEX "IDX_blocking_reaction_user_blockeeid";`); | ||
await queryRunner.query(`DROP INDEX "IDX_blocking_reaction_user_id";`); | ||
await queryRunner.query(`ALTER TABLE "blocking_reaction_user" DROP CONSTRAINT "FK_blocking_reaction_user_blockerid";`); | ||
await queryRunner.query(`ALTER TABLE "blocking_reaction_user" DROP CONSTRAINT "FK_blocking_reaction_user_blockeeid";`); | ||
await queryRunner.query(`ALTER TABLE "blocking_reaction_user" DROP CONSTRAINT "PK_blocking_reaction_user";`); | ||
await queryRunner.query(`DROP TABLE "blocking_reaction_user";`); | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
packages/backend/src/core/BlockingReactionUserService.ts
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,110 @@ | ||
/* | ||
* SPDX-FileCopyrightText: syuilo and misskey-project | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
import { Inject, Injectable, OnModuleInit } from '@nestjs/common'; | ||
import { ModuleRef } from '@nestjs/core'; | ||
import { IdService } from '@/core/IdService.js'; | ||
import type { MiUser } from '@/models/User.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, | ||
BlockingReactionUsersRepository | ||
} from '@/models/_.js'; | ||
import Logger from '@/logger.js'; | ||
import { UserEntityService } from '@/core/entities/UserEntityService.js'; | ||
import { ApRendererService } from '@/core/activitypub/ApRendererService.js'; | ||
import { LoggerService } from '@/core/LoggerService.js'; | ||
import { UserWebhookService } from '@/core/UserWebhookService.js'; | ||
import { bindThis } from '@/decorators.js'; | ||
import { CacheService } from '@/core/CacheService.js'; | ||
import {MiBlockingReactionUser} from "@/models/_.js"; | ||
|
||
@Injectable() | ||
export class BlockingReactionUserService implements OnModuleInit { | ||
private logger: Logger; | ||
|
||
constructor( | ||
private moduleRef: ModuleRef, | ||
|
||
@Inject(DI.blockingReactionUsersRepository) | ||
private blockingReactionUsersRepository: BlockingReactionUsersRepository, | ||
|
||
private cacheService: CacheService, | ||
private userEntityService: UserEntityService, | ||
private idService: IdService, | ||
private queueService: QueueService, | ||
private globalEventService: GlobalEventService, | ||
private webhookService: UserWebhookService, | ||
private apRendererService: ApRendererService, | ||
private loggerService: LoggerService, | ||
) { | ||
this.logger = this.loggerService.getLogger('user-block'); | ||
} | ||
|
||
onModuleInit() { | ||
} | ||
|
||
@bindThis | ||
public async block(blocker: MiUser, blockee: MiUser, silent = false) { | ||
await Promise.all([ | ||
]); | ||
|
||
const blocking = { | ||
id: this.idService.gen(), | ||
blocker, | ||
blockerId: blocker.id, | ||
blockee, | ||
blockeeId: blockee.id, | ||
} as MiBlockingReactionUser; | ||
|
||
await this.blockingReactionUsersRepository.insert(blocking); | ||
|
||
this.cacheService.blockingReactionUserCache.refresh(blocker.id); | ||
this.cacheService.blockedReactionUserCache.refresh(blockee.id); | ||
|
||
this.globalEventService.publishInternalEvent('blockingReactionUserCreated', { | ||
blockerId: blocker.id, | ||
blockeeId: blockee.id, | ||
}); | ||
} | ||
|
||
@bindThis | ||
public async unblock(blocker: MiUser, blockee: MiUser) { | ||
const blocking = await this.blockingReactionUsersRepository.findOneBy({ | ||
blockerId: blocker.id, | ||
blockeeId: blockee.id, | ||
}); | ||
|
||
if (blocking == null) { | ||
this.logger.warn('ブロック解除がリクエストされましたがブロックしていませんでした'); | ||
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.blockingReactionUsersRepository.delete(blocking.id); | ||
|
||
this.cacheService.blockingReactionUserCache.refresh(blocker.id); | ||
this.cacheService.blockedReactionUserCache.refresh(blockee.id); | ||
|
||
this.globalEventService.publishInternalEvent('blockingReactionUserDeleted', { | ||
blockerId: blocker.id, | ||
blockeeId: blockee.id, | ||
}); | ||
} | ||
|
||
@bindThis | ||
public async checkBlocked(blockerId: MiUser['id'], blockeeId: MiUser['id']): Promise<boolean> { | ||
return (await this.cacheService.blockingReactionUserCache.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
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.