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

View File

@@ -28,7 +28,6 @@ implements OnGatewayConnection, OnGatewayDisconnect
}
async handleDisconnect(socket: socketDto) {
this.sockets.delete(socket.username);
console.log('- socket disconnected :', socket.id, socket.username);
}
@SubscribeMessage('join')
@@ -41,8 +40,6 @@ implements OnGatewayConnection, OnGatewayDisconnect
let message = `${socket.username} has join the room`;
await socket.to(socket.room).emit('message', "SERVER", message);
await this.chatService.addMessageToRoom(room_name, "SERVER", message);
console.log('- out joinRoom gateway');
}
@SubscribeMessage('change')
@@ -50,8 +47,6 @@ implements OnGatewayConnection, OnGatewayDisconnect
{
console.log('- in changeRoom gateway');
await this.chatService.socketChangeRoom(socket, room_name);
console.log('- out changeRoom gateway');
}
@SubscribeMessage('message')
@@ -59,8 +54,6 @@ implements OnGatewayConnection, OnGatewayDisconnect
{
console.log('- in handleMessage gateway');
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}%` })
.getMany();
console.log("-- out getMyRooms service");
return rooms;
}
@@ -49,7 +48,6 @@ export class ChatService {
const my_rooms = await this.getMyRooms(username);
const directs = my_rooms.filter(room => room.type === 'direct');
console.log("-- out getAllNotMyRooms service");
return directs;
}
@@ -60,7 +58,6 @@ export class ChatService {
.createQueryBuilder('chatroom')
.getMany();
console.log("-- out getAllRooms service");
return rooms;
}
@@ -74,7 +71,6 @@ export class ChatService {
.andWhere('chatroom.users NOT LIKE :user_name', { user_name: `%${username}%` })
.getMany();
console.log("-- out getAllNotMyRooms service");
return rooms;
}
@@ -82,10 +78,8 @@ export class ChatService {
{
console.log("-- in getMessagesFromCurrentRoom service");
const user_db = await this.getUserByName(username);
//const user_db = await this.usersService.findOne(username);
const currentRoom = await this.getRoomByName(user_db.currentRoom);
console.log("-- out getMessagesFromCurrentRoom service");
return currentRoom.messages;
}
@@ -94,9 +88,7 @@ export class ChatService {
console.log("-- in getCurrentRoomName service");
console.log('username:', 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;
}
@@ -108,7 +100,6 @@ export class ChatService {
.where('chatroom.name = :name', { name: room_name })
.getOne();
console.log("-- out getRoomByName service");
return room;
}
@@ -120,7 +111,6 @@ export class ChatService {
.where('chatroom.id = :id', { id: id })
.getOne();
console.log("-- out getRoomById service");
return room;
}
@@ -132,11 +122,9 @@ export class ChatService {
{
console.log("-- in setCurrentRoom service");
const user_db = await this.getUserByName(username);
//const user_db = await this.usersService.findOne(username);
user_db.currentRoom = room_name;
this.userRepository.save(user_db);
console.log("-- out setCurrentRoom service");
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}` }];
this.chatroomRepository.save(newChatroom);
console.log("-- out addUserToNewRoom service");
return "successfull room creation";
}
@@ -177,7 +164,6 @@ export class ChatService {
await this.setCurrentRoom(username, room_name);
console.log("-- out addUserToRoom service");
return "successfully joining room";
}
@@ -191,8 +177,6 @@ export class ChatService {
};
currentRoom.messages.push(chat_message);
this.chatroomRepository.save(currentRoom);
console.log("-- out addMessageToRoom service");
}
@@ -214,7 +198,6 @@ export class ChatService {
// set current room to nothing
await this.setCurrentRoom(username, "");
console.log("-- out removeUserFromRoom service");
return "successfully leaving room";
}
@@ -230,11 +213,10 @@ export class ChatService {
.where('user.username = :name', { name: username })
.getOne();
console.log("-- out getUserByName service");
return user;
}
async getAllUsersNotMyRooms(username: string)
async getAllUsersNotMyRooms(username: string): Promise<User[]>
{
console.log("-- in getAllUsersNotMyRooms service");
@@ -244,34 +226,15 @@ export class ChatService {
usernames = [""];
console.log("usernames:", usernames);
const my_users = await this.userRepository
const users = await this.userRepository
.createQueryBuilder('user')
.where('user.username NOT IN (:...usernames)', { usernames: usernames })
.getMany();
console.log("my_users:", my_users);
console.log("users:", 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");
return users;
}
/*
*/
/* GATEWAY EVENTS *****************************************
@@ -284,8 +247,6 @@ export class ChatService {
socket.to(socket.room).emit('message', socket.username, message);
let room_name = await this.getCurrentRoomName(socket.username);
await this.addMessageToRoom(room_name, socket.username, message);
console.log("-- out handleSocketIncommingMessage service");
}
async socketChangeRoom(socket: socketDto, room_name: string): Promise<void>
@@ -295,8 +256,6 @@ export class ChatService {
socket.leave(socket.room);
socket.join(room_name);
socket.room = room_name;
console.log('-- out socketChangeRoom service');
}
async socketJoinRoom(socket: socketDto, room_name: string): Promise<void>
@@ -309,8 +268,6 @@ export class ChatService {
let message = `${socket.username} has join the room`;
await socket.to(socket.room).emit('message', "SERVER", message);
await this.addMessageToRoom(room_name, "SERVER", message);
console.log('- out socketJoinRoom service');
}
}