@@ -47,7 +47,7 @@ export class ChatGateway implements OnGatewayInit, OnGatewayConnection, OnGatewa
47
47
48
48
async handleConnection ( client : Socket ) {
49
49
console . log ( `Client connected: ${ client . id } ` ) ;
50
- const user = await this . roomService . createUser ( client . id ) ;
50
+ const user = await this . roomService . createUser ( client ) ;
51
51
console . log ( user ) ;
52
52
53
53
/*
@@ -102,7 +102,9 @@ export class ChatGateway implements OnGatewayInit, OnGatewayConnection, OnGatewa
102
102
const user = await this . roomService . getUserByClientId ( client . id ) ;
103
103
const normalOutgoingMessage : Omit < NormalOutgoingMessageDto , 'owner' > = {
104
104
roomId,
105
- ...user ,
105
+ nickname : user . nickname ,
106
+ color : user . color ,
107
+ entryTime : user . entryTime ,
106
108
msg,
107
109
msgTime : new Date ( ) . toISOString ( ) ,
108
110
msgType : 'normal' ,
@@ -131,7 +133,9 @@ export class ChatGateway implements OnGatewayInit, OnGatewayConnection, OnGatewa
131
133
const user = await this . roomService . getUserByClientId ( client . id ) ;
132
134
const questionWithoutId : Omit < QuestionDto , 'questionId' > = {
133
135
roomId,
134
- ...user ,
136
+ nickname : user . nickname ,
137
+ color : user . color ,
138
+ entryTime : user . entryTime ,
135
139
msg,
136
140
msgTime : new Date ( ) . toISOString ( ) ,
137
141
msgType : 'question' ,
@@ -161,7 +165,9 @@ export class ChatGateway implements OnGatewayInit, OnGatewayConnection, OnGatewa
161
165
const user = await this . roomService . getUserByClientId ( client . id ) ;
162
166
const noticeOutgoingMessage : NoticeOutgoingMessageDto = {
163
167
roomId,
164
- ...user ,
168
+ nickname : user . nickname ,
169
+ color : user . color ,
170
+ entryTime : user . entryTime ,
165
171
msg,
166
172
msgTime : new Date ( ) . toISOString ( ) ,
167
173
msgType : 'notice'
@@ -173,12 +179,10 @@ export class ChatGateway implements OnGatewayInit, OnGatewayConnection, OnGatewa
173
179
@SubscribeMessage ( CHATTING_SOCKET_DEFAULT_EVENT . BAN_USER )
174
180
async handleBanUserMessage ( @ConnectedSocket ( ) client : Socket , @MessageBody ( ) payload : BanUserIncomingMessageDto ) {
175
181
const { roomId, socketId } = payload ;
176
- const banUser = this . server . sockets . sockets . get ( socketId ) ;
177
- const address = banUser ?. handshake . address . replaceAll ( '::ffff:' , '' ) ;
178
-
179
- if ( ! address ) throw new ChatException ( CHATTING_SOCKET_ERROR . INVALID_USER , roomId ) ;
180
-
181
- const userAgent = banUser ?. handshake . headers [ 'user-agent' ] ;
182
+ const banUser = await this . roomService . getUserByClientId ( socketId ) ;
183
+ console . log ( 'banUSer = ' , banUser ) ;
184
+ if ( ! banUser ) throw new ChatException ( CHATTING_SOCKET_ERROR . INVALID_USER , roomId ) ;
185
+ const { address, userAgent } = banUser ;
182
186
if ( ! userAgent ) throw new ChatException ( CHATTING_SOCKET_ERROR . INVALID_USER , roomId ) ;
183
187
184
188
await this . roomService . addUserToBlacklist ( roomId , address , userAgent ) ;
0 commit comments