wip bock user

This commit is contained in:
simplonco
2023-01-16 08:13:10 +01:00
parent cc389a67b7
commit fe44a9b21c
5 changed files with 29 additions and 3 deletions

View File

@@ -525,5 +525,19 @@ export class ChatController {
printCaller("- out ");
}
@UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard)
@Post('block')
async blockUser(@Body('username') username: string, @Req() req, @Res() res): Promise<void>
{
printCaller("- in ");
let user_socket: socketDto = this.chatGateway.sockets.get(req.user.username);
user_socket.join(`${username}_not_emit`);
res.status(HttpStatus.OK).json({ message: "successfull unmute" });
printCaller("- out ");
}
}

View File

@@ -25,6 +25,9 @@ implements OnGatewayConnection, OnGatewayDisconnect
console.log('- socket connected :', socket.id, socket.handshake.query.username);
socket.username = socket.handshake.query.username.toString();
this.sockets.set(socket.username, socket);
let not_emit: string = `${socket.username}_not_emit`;
socket.join(not_emit);
}
async handleDisconnect(socket: socketDto) {
this.sockets.delete(socket.username);

View File

@@ -561,7 +561,7 @@ export class ChatService {
socket.join(room_name);
socket.room = room_name;
let message = `${socket.username} joined the room`;
await socket.to(socket.room).emit('message', "SERVER", message);
await socket.to(socket.room).except(`${socket.username}_not_emit`).emit('message', "SERVER", message);
await this.addMessageToRoom(room_name, "SERVER", message);
printCaller("-- out ");