88import { Server , Socket } from 'socket.io' ;
99import { ChatRoomService } from './chat-room/chat-room.service' ;
1010import { ChatMessageService } from './chat-message/chat-message.service' ;
11+ import { UserService } from './user/user.service' ;
12+ import { UserBlockService } from './user-block/user-block.service' ;
1113
1214//클라이언트의 패킷들이 게이트웨이를 통해서 들어오게 됩니다.
1315@WebSocketGateway ( { namespace : '/socket/chatting' } )
@@ -19,6 +21,8 @@ export class EventsGateway implements OnGatewayConnection, OnGatewayDisconnect {
1921 constructor (
2022 private readonly chatRoomService : ChatRoomService ,
2123 private readonly chatMessageService : ChatMessageService ,
24+ private readonly userService : UserService ,
25+ private readonly userBlockService : UserBlockService ,
2226 ) { }
2327 /*
2428 유저정보는 같지만 소켓이 여러개가 연결되어 있을 경우
@@ -74,6 +78,16 @@ export class EventsGateway implements OnGatewayConnection, OnGatewayDisconnect {
7478 } ,
7579 ) {
7680 const { chatRoomId, toUserId, content, fromUserId, createdAt } = payload ;
81+ const toUser = await this . userService . getUserById ( toUserId ) ;
82+ const blockedUserIds =
83+ await this . userBlockService . getBlockedUserIds ( toUserId ) ;
84+ if ( ! toUser || blockedUserIds . includes ( fromUserId ) ) {
85+ const errorMessage = ! toUser
86+ ? '존재하지 않는 사용자입니다.'
87+ : '차단된 사용자에게 메시지를 보낼 수 없습니다.' ;
88+ client . emit ( 'error' , errorMessage ) ;
89+ return ;
90+ }
7791
7892 // 메시지 저장 로직
7993 const newMessage = await this . chatMessageService . saveMessage (
0 commit comments