diff --git a/packages/backend/src/core/ChatService.ts b/packages/backend/src/core/ChatService.ts index f5b9cf7e8d..37288b75fe 100644 --- a/packages/backend/src/core/ChatService.ts +++ b/packages/backend/src/core/ChatService.ts @@ -67,8 +67,15 @@ export class ChatService { if (toUser.chatScope === 'none') { throw new Error('recipient is cannot chat'); } else if (toUser.chatScope === 'followers') { - + const isFollower = await this.userFollowingService.isFollowing(fromUser.id, toUser.id); + if (!isFollower) { + throw new Error('recipient is cannot chat'); + } } else if (toUser.chatScope === 'following') { + const isFollowing = await this.userFollowingService.isFollowing(toUser.id, fromUser.id); + if (!isFollowing) { + throw new Error('recipient is cannot chat'); + } } else if (toUser.chatScope === 'mutual') { const isMutual = await this.userFollowingService.isMutual(fromUser.id, toUser.id); if (!isMutual) { diff --git a/packages/backend/src/core/UserFollowingService.ts b/packages/backend/src/core/UserFollowingService.ts index aac340f079..e7a6be99fb 100644 --- a/packages/backend/src/core/UserFollowingService.ts +++ b/packages/backend/src/core/UserFollowingService.ts @@ -737,6 +737,16 @@ export class UserFollowingService implements OnModuleInit { .getMany(); } + @bindThis + public isFollowing(followerId: MiUser['id'], followeeId: MiUser['id']) { + return this.followingsRepository.exists({ + where: { + followerId, + followeeId, + }, + }); + } + @bindThis public async isMutual(aUserId: MiUser['id'], bUserId: MiUser['id']) { const count = await this.followingsRepository.createQueryBuilder('following')