small cleanup

This commit is contained in:
simplonco
2023-01-10 23:03:43 +01:00
parent 7f01ccdb78
commit 9aad7019ab
3 changed files with 6 additions and 66 deletions

View File

@@ -32,7 +32,6 @@ export class ChatController {
{ {
console.log("- in getMyRooms controller"); console.log("- in getMyRooms controller");
const rooms = await this.chatService.getMyRooms(req.user.username); const rooms = await this.chatService.getMyRooms(req.user.username);
console.log("- out getMyRooms controller");
return res.status(HttpStatus.OK).json({ rooms: rooms }); return res.status(HttpStatus.OK).json({ rooms: rooms });
} }
@@ -43,9 +42,8 @@ export class ChatController {
{ {
console.log("- in getAllRooms controller"); console.log("- in getAllRooms controller");
const rooms = await this.chatService.getAllNotMyRooms(req.user.username); const rooms = await this.chatService.getAllNotMyRooms(req.user.username);
await this.chatService.getAllUsersNotMyRooms(req.user.username); const directs = await this.chatService.getAllUsersNotMyRooms(req.user.username);
console.log("- out getAllRooms controller"); return res.status(HttpStatus.OK).json({ rooms: rooms, directs: directs });
return res.status(HttpStatus.OK).json({ rooms: rooms });
} }
@UseGuards(AuthenticateGuard) @UseGuards(AuthenticateGuard)
@@ -55,7 +53,6 @@ export class ChatController {
{ {
console.log("- in setCurrentRoom controller"); console.log("- in setCurrentRoom controller");
const response = await this.chatService.setCurrentRoom(req.user.username, setCurrentRoomDto.name); const response = await this.chatService.setCurrentRoom(req.user.username, setCurrentRoomDto.name);
console.log("- out setCurrentRoom controller");
return res.status(HttpStatus.OK).json({ message: response }); return res.status(HttpStatus.OK).json({ message: response });
} }
@@ -65,7 +62,6 @@ export class ChatController {
async allowedChars(@Res() res): Promise<object> async allowedChars(@Res() res): Promise<object>
{ {
console.log("- in allowedChars controller"); console.log("- in allowedChars controller");
console.log("- out allowedChars controller");
return res.status(HttpStatus.OK).json({ chars: this.allowed_chars }); return res.status(HttpStatus.OK).json({ chars: this.allowed_chars });
} }
@@ -86,7 +82,6 @@ export class ChatController {
} }
const response = await this.chatService.addUserToNewRoom(req.user.username, createRoomDto); const response = await this.chatService.addUserToNewRoom(req.user.username, createRoomDto);
console.log("- out createRoom controller");
return res.status(HttpStatus.OK).json({ room_name: createRoomDto.room_name, message: response }); return res.status(HttpStatus.OK).json({ room_name: createRoomDto.room_name, message: response });
} }
@@ -101,7 +96,6 @@ export class ChatController {
let socket: socketDto = this.chatGateway.sockets.get(req.user.username); let socket: socketDto = this.chatGateway.sockets.get(req.user.username);
await this.chatService.socketJoinRoom(socket, joinRoomDto.room_name); await this.chatService.socketJoinRoom(socket, joinRoomDto.room_name);
console.log("- out joinRoom controller");
return res.status(HttpStatus.OK).json({ room_name: joinRoomDto.room_name, message: response }); return res.status(HttpStatus.OK).json({ room_name: joinRoomDto.room_name, message: response });
} }
@@ -116,7 +110,6 @@ export class ChatController {
let socket: socketDto = this.chatGateway.sockets.get(req.user.username); let socket: socketDto = this.chatGateway.sockets.get(req.user.username);
await this.chatService.socketChangeRoom(socket, joinRoomDto.room_name); await this.chatService.socketChangeRoom(socket, joinRoomDto.room_name);
console.log("- out changeRoom controller");
return res.status(HttpStatus.OK).json({ room_name: joinRoomDto.room_name, message: response }); return res.status(HttpStatus.OK).json({ room_name: joinRoomDto.room_name, message: response });
} }
@@ -136,7 +129,6 @@ export class ChatController {
{ {
console.log("- in getMessages controller"); console.log("- in getMessages controller");
const messages = await this.chatService.getMessagesFromCurrentRoom(req.user.username); const messages = await this.chatService.getMessagesFromCurrentRoom(req.user.username);
console.log("- out getMessages controller");
return res.status(HttpStatus.OK).json({ messages: messages }); return res.status(HttpStatus.OK).json({ messages: messages });
} }
@@ -149,7 +141,6 @@ export class ChatController {
const room_name = await this.chatService.getCurrentRoomName(req.user.username); const room_name = await this.chatService.getCurrentRoomName(req.user.username);
const room = await this.chatService.getRoomByName(room_name); const room = await this.chatService.getRoomByName(room_name);
const users = room.users; const users = room.users;
console.log("- out getRoomUsers controller");
return res.status(HttpStatus.OK).json({ users: users }); return res.status(HttpStatus.OK).json({ users: users });
} }
@@ -161,7 +152,6 @@ export class ChatController {
console.log("- in removeUser controller"); console.log("- in removeUser controller");
const room_name = await this.chatService.getCurrentRoomName(req.user.username); const room_name = await this.chatService.getCurrentRoomName(req.user.username);
let response = await this.chatService.removeUserFromRoom(req.user.username, room_name); let response = await this.chatService.removeUserFromRoom(req.user.username, room_name);
console.log("- out removeUser controller");
return res.status(HttpStatus.OK).json({ message: response }); return res.status(HttpStatus.OK).json({ message: response });
} }

View File

@@ -28,7 +28,6 @@ implements OnGatewayConnection, OnGatewayDisconnect
} }
async handleDisconnect(socket: socketDto) { async handleDisconnect(socket: socketDto) {
this.sockets.delete(socket.username); this.sockets.delete(socket.username);
console.log('- socket disconnected :', socket.id, socket.username);
} }
@SubscribeMessage('join') @SubscribeMessage('join')
@@ -41,8 +40,6 @@ implements OnGatewayConnection, OnGatewayDisconnect
let message = `${socket.username} has join the room`; let message = `${socket.username} has join the room`;
await socket.to(socket.room).emit('message', "SERVER", message); await socket.to(socket.room).emit('message', "SERVER", message);
await this.chatService.addMessageToRoom(room_name, "SERVER", message); await this.chatService.addMessageToRoom(room_name, "SERVER", message);
console.log('- out joinRoom gateway');
} }
@SubscribeMessage('change') @SubscribeMessage('change')
@@ -50,8 +47,6 @@ implements OnGatewayConnection, OnGatewayDisconnect
{ {
console.log('- in changeRoom gateway'); console.log('- in changeRoom gateway');
await this.chatService.socketChangeRoom(socket, room_name); await this.chatService.socketChangeRoom(socket, room_name);
console.log('- out changeRoom gateway');
} }
@SubscribeMessage('message') @SubscribeMessage('message')
@@ -59,8 +54,6 @@ implements OnGatewayConnection, OnGatewayDisconnect
{ {
console.log('- in handleMessage gateway'); console.log('- in handleMessage gateway');
await this.chatService.socketIncommingMessage(socket, message); await this.chatService.socketIncommingMessage(socket, message);
console.log('- out handleMessage gateway');
} }
} }

View File

@@ -39,7 +39,6 @@ export class ChatService {
.where('chatroom.users LIKE :user_name', { user_name: `%${username}%` }) .where('chatroom.users LIKE :user_name', { user_name: `%${username}%` })
.getMany(); .getMany();
console.log("-- out getMyRooms service");
return rooms; return rooms;
} }
@@ -49,7 +48,6 @@ export class ChatService {
const my_rooms = await this.getMyRooms(username); const my_rooms = await this.getMyRooms(username);
const directs = my_rooms.filter(room => room.type === 'direct'); const directs = my_rooms.filter(room => room.type === 'direct');
console.log("-- out getAllNotMyRooms service");
return directs; return directs;
} }
@@ -60,7 +58,6 @@ export class ChatService {
.createQueryBuilder('chatroom') .createQueryBuilder('chatroom')
.getMany(); .getMany();
console.log("-- out getAllRooms service");
return rooms; return rooms;
} }
@@ -74,7 +71,6 @@ export class ChatService {
.andWhere('chatroom.users NOT LIKE :user_name', { user_name: `%${username}%` }) .andWhere('chatroom.users NOT LIKE :user_name', { user_name: `%${username}%` })
.getMany(); .getMany();
console.log("-- out getAllNotMyRooms service");
return rooms; return rooms;
} }
@@ -82,10 +78,8 @@ export class ChatService {
{ {
console.log("-- in getMessagesFromCurrentRoom service"); console.log("-- in getMessagesFromCurrentRoom service");
const user_db = await this.getUserByName(username); const user_db = await this.getUserByName(username);
//const user_db = await this.usersService.findOne(username);
const currentRoom = await this.getRoomByName(user_db.currentRoom); const currentRoom = await this.getRoomByName(user_db.currentRoom);
console.log("-- out getMessagesFromCurrentRoom service");
return currentRoom.messages; return currentRoom.messages;
} }
@@ -94,9 +88,7 @@ export class ChatService {
console.log("-- in getCurrentRoomName service"); console.log("-- in getCurrentRoomName service");
console.log('username:', username); console.log('username:', username);
const user_db = await this.getUserByName(username); const user_db = await this.getUserByName(username);
//const user_db = await this.usersService.findOne(username);
console.log("-- out getCurrentRoomName service");
return user_db.currentRoom; return user_db.currentRoom;
} }
@@ -108,7 +100,6 @@ export class ChatService {
.where('chatroom.name = :name', { name: room_name }) .where('chatroom.name = :name', { name: room_name })
.getOne(); .getOne();
console.log("-- out getRoomByName service");
return room; return room;
} }
@@ -120,7 +111,6 @@ export class ChatService {
.where('chatroom.id = :id', { id: id }) .where('chatroom.id = :id', { id: id })
.getOne(); .getOne();
console.log("-- out getRoomById service");
return room; return room;
} }
@@ -132,11 +122,9 @@ export class ChatService {
{ {
console.log("-- in setCurrentRoom service"); console.log("-- in setCurrentRoom service");
const user_db = await this.getUserByName(username); const user_db = await this.getUserByName(username);
//const user_db = await this.usersService.findOne(username);
user_db.currentRoom = room_name; user_db.currentRoom = room_name;
this.userRepository.save(user_db); this.userRepository.save(user_db);
console.log("-- out setCurrentRoom service");
return `room "${room_name}" is now current room`; return `room "${room_name}" is now current room`;
} }
@@ -160,7 +148,6 @@ export class ChatService {
newChatroom.messages = [{ name: "SERVER", message: `creation of room ${createRoomDto.room_name}` }]; newChatroom.messages = [{ name: "SERVER", message: `creation of room ${createRoomDto.room_name}` }];
this.chatroomRepository.save(newChatroom); this.chatroomRepository.save(newChatroom);
console.log("-- out addUserToNewRoom service");
return "successfull room creation"; return "successfull room creation";
} }
@@ -177,7 +164,6 @@ export class ChatService {
await this.setCurrentRoom(username, room_name); await this.setCurrentRoom(username, room_name);
console.log("-- out addUserToRoom service");
return "successfully joining room"; return "successfully joining room";
} }
@@ -191,8 +177,6 @@ export class ChatService {
}; };
currentRoom.messages.push(chat_message); currentRoom.messages.push(chat_message);
this.chatroomRepository.save(currentRoom); this.chatroomRepository.save(currentRoom);
console.log("-- out addMessageToRoom service");
} }
@@ -214,7 +198,6 @@ export class ChatService {
// set current room to nothing // set current room to nothing
await this.setCurrentRoom(username, ""); await this.setCurrentRoom(username, "");
console.log("-- out removeUserFromRoom service");
return "successfully leaving room"; return "successfully leaving room";
} }
@@ -230,11 +213,10 @@ export class ChatService {
.where('user.username = :name', { name: username }) .where('user.username = :name', { name: username })
.getOne(); .getOne();
console.log("-- out getUserByName service");
return user; return user;
} }
async getAllUsersNotMyRooms(username: string) async getAllUsersNotMyRooms(username: string): Promise<User[]>
{ {
console.log("-- in getAllUsersNotMyRooms service"); console.log("-- in getAllUsersNotMyRooms service");
@@ -244,35 +226,16 @@ export class ChatService {
usernames = [""]; usernames = [""];
console.log("usernames:", usernames); console.log("usernames:", usernames);
const my_users = await this.userRepository const users = await this.userRepository
.createQueryBuilder('user') .createQueryBuilder('user')
.where('user.username NOT IN (:...usernames)', { usernames: usernames }) .where('user.username NOT IN (:...usernames)', { usernames: usernames })
.getMany(); .getMany();
console.log("my_users:", my_users); console.log("users:", users);
/* return users;
User {
id: 1,
fortyTwoId: '42522',
username: 'hulamy',
email: 'hulamy@student.42.fr',
image_url: 'default.png',
phone: null,
status: 'Connected',
isEnabledTwoFactorAuth: false,
isTwoFactorAuthenticated: false,
secretTwoFactorAuth: null,
currentRoom: 'hugo2'
} }
*/
console.log("-- out getAllUsersNotMyRooms service");
}
/*
*/
/* GATEWAY EVENTS ***************************************** /* GATEWAY EVENTS *****************************************
*/ */
@@ -284,8 +247,6 @@ export class ChatService {
socket.to(socket.room).emit('message', socket.username, message); socket.to(socket.room).emit('message', socket.username, message);
let room_name = await this.getCurrentRoomName(socket.username); let room_name = await this.getCurrentRoomName(socket.username);
await this.addMessageToRoom(room_name, socket.username, message); await this.addMessageToRoom(room_name, socket.username, message);
console.log("-- out handleSocketIncommingMessage service");
} }
async socketChangeRoom(socket: socketDto, room_name: string): Promise<void> async socketChangeRoom(socket: socketDto, room_name: string): Promise<void>
@@ -295,8 +256,6 @@ export class ChatService {
socket.leave(socket.room); socket.leave(socket.room);
socket.join(room_name); socket.join(room_name);
socket.room = room_name; socket.room = room_name;
console.log('-- out socketChangeRoom service');
} }
async socketJoinRoom(socket: socketDto, room_name: string): Promise<void> async socketJoinRoom(socket: socketDto, room_name: string): Promise<void>
@@ -309,8 +268,6 @@ export class ChatService {
let message = `${socket.username} has join the room`; let message = `${socket.username} has join the room`;
await socket.to(socket.room).emit('message', "SERVER", message); await socket.to(socket.room).emit('message', "SERVER", message);
await this.addMessageToRoom(room_name, "SERVER", message); await this.addMessageToRoom(room_name, "SERVER", message);
console.log('- out socketJoinRoom service');
} }
} }