Skip to content

Commit

Permalink
enhance: ブロックと同時にミュートするように (#114)
Browse files Browse the repository at this point in the history
Co-authored-by: Esurio <esurio@esurio1673.net>
  • Loading branch information
1673beta and Esurio authored Jul 31, 2024
1 parent ab3c5e5 commit c5881c7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG_engawa.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
- CherryPick 4.10.0-beta.2に追従しました
- ユーザーにセンシティブフラグが付けられるようになりました
- 有効にすると、投稿は自動的にCWがつくようになります
- `blocking/create`でブロックした際、同時にミュートするようになりました
- `blocking/delete`をしてもミュートは解除されません。

### Client
-
Expand Down
21 changes: 19 additions & 2 deletions packages/backend/src/server/api/endpoints/blocking/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import ms from 'ms';
import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import type { UsersRepository, BlockingsRepository } from '@/models/_.js';
import type { UsersRepository, BlockingsRepository, MutingsRepository } from '@/models/_.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { UserBlockingService } from '@/core/UserBlockingService.js';
import { UserMutingService } from '@/core/UserMutingService.js';
import { DI } from '@/di-symbols.js';
import { GetterService } from '@/server/api/GetterService.js';
import { ApiError } from '../../error.js';
Expand Down Expand Up @@ -69,9 +70,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
@Inject(DI.blockingsRepository)
private blockingsRepository: BlockingsRepository,

@Inject(DI.mutingsRepository)
private mutingsRepository: MutingsRepository,

private userEntityService: UserEntityService,
private getterService: GetterService,
private userBlockingService: UserBlockingService,
private userMutingService: UserMutingService,
) {
super(meta, paramDef, async (ps, me) => {
const blocker = await this.usersRepository.findOneByOrFail({ id: me.id });
Expand Down Expand Up @@ -99,7 +104,19 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.alreadyBlocking);
}

await this.userBlockingService.block(blocker, blockee);
await Promise.all([
this.userBlockingService.block(blocker, blockee),
this.mutingsRepository.exists({
where: {
muteeId: blockee.id,
muterId: blocker.id,
},
}).then(exists => {
if (!exists) {
this.userMutingService.mute(blocker, blockee, null);
}
}),
]);

return await this.userEntityService.pack(blockee.id, blocker, {
schema: 'UserDetailedNotMe',
Expand Down

0 comments on commit c5881c7

Please sign in to comment.