wip invite, and join room gives 2 messages
This commit is contained in:
@@ -150,11 +150,11 @@ export class ChatController {
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Post('invite')
|
||||
async inviteUser(@Body() username: string, @Req() req, @Res() res): Promise<void>
|
||||
async inviteUser(@Body('username') username: string, @Req() req, @Res() res): Promise<void>
|
||||
{
|
||||
console.log("- in inviteUser controller");
|
||||
|
||||
let current_room_name = await this.chatService.getCurrentRoomName(username);
|
||||
let current_room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
||||
await this.chatService.addUserToRoom(username, current_room_name);
|
||||
|
||||
res.status(HttpStatus.OK);
|
||||
|
||||
@@ -147,7 +147,9 @@ export class ChatService {
|
||||
{
|
||||
console.log("-- in getCurrentRoomName service");
|
||||
|
||||
console.log("username:", username);
|
||||
const user_db = await this.getUserByName(username);
|
||||
console.log("user_db:", user_db);
|
||||
|
||||
console.log("-- out getCurrentRoomName service");
|
||||
return user_db.currentRoom;
|
||||
@@ -157,11 +159,12 @@ export class ChatService {
|
||||
{
|
||||
console.log("-- in getRoomByName service");
|
||||
|
||||
console.log("room_name:", room_name);
|
||||
const room = await this.chatroomRepository
|
||||
.createQueryBuilder('chatroom')
|
||||
.where('chatroom.name = :name', { name: room_name })
|
||||
.getOne();
|
||||
console.log("--- room:", room);
|
||||
console.log("room:", room);
|
||||
|
||||
console.log("-- out getRoomByName service");
|
||||
return room;
|
||||
@@ -175,7 +178,6 @@ export class ChatService {
|
||||
.createQueryBuilder('chatroom')
|
||||
.where('chatroom.id = :id', { id: id })
|
||||
.getOne();
|
||||
console.log("--- room:", room);
|
||||
|
||||
console.log("-- out getRoomById service");
|
||||
return room;
|
||||
@@ -192,7 +194,7 @@ export class ChatService {
|
||||
const user_db = await this.getUserByName(username);
|
||||
user_db.currentRoom = room_name;
|
||||
this.userRepository.save(user_db);
|
||||
|
||||
|
||||
console.log("-- out setCurrentRoom service");
|
||||
return `room "${room_name}" is now current room`;
|
||||
}
|
||||
@@ -210,12 +212,15 @@ export class ChatService {
|
||||
throw new HttpException(`This room name already exist`, HttpStatus.CONFLICT);
|
||||
|
||||
// create chatroom
|
||||
const newChatroom = new Chatroom();
|
||||
let newChatroom = new Chatroom();
|
||||
newChatroom.name = room.name;
|
||||
newChatroom.type = room.type;
|
||||
newChatroom.owner = room.owner;
|
||||
newChatroom.users = room.users;
|
||||
newChatroom.messages = [{ name: "SERVER", message: `creation of room ${room.name}` }];
|
||||
newChatroom.messages = [
|
||||
{ name: "SERVER", message: `creation of room ${room.name}` },
|
||||
{ name: "SERVER", message: `${room.users[0]} joined the room` },
|
||||
];
|
||||
await this.chatroomRepository.save(newChatroom);
|
||||
|
||||
console.log("-- out addUserToNewRoom service");
|
||||
@@ -231,6 +236,7 @@ export class ChatService {
|
||||
|
||||
// update room with new user
|
||||
room.users.push(username);
|
||||
room.messages.push({ name: "SERVER", message: `${username} joined the room`});
|
||||
this.chatroomRepository.save(room);
|
||||
|
||||
console.log("-- out addUserToRoom service");
|
||||
@@ -290,7 +296,6 @@ export class ChatService {
|
||||
.createQueryBuilder('user')
|
||||
.where('user.username = :name', { name: username })
|
||||
.getOne();
|
||||
console.log("--- user:", user);
|
||||
|
||||
console.log("-- out getUserByName service");
|
||||
return user;
|
||||
@@ -372,7 +377,7 @@ export class ChatService {
|
||||
socket.leave(socket.room);
|
||||
socket.join(room_name);
|
||||
socket.room = room_name;
|
||||
let message = `${socket.username} has join the room`;
|
||||
let message = `${socket.username} joined the room`;
|
||||
await socket.to(socket.room).emit('message', "SERVER", message);
|
||||
await this.addMessageToRoom(room_name, "SERVER", message);
|
||||
|
||||
|
||||
@@ -13,11 +13,8 @@
|
||||
{
|
||||
console.log("inside invite_this_user");
|
||||
|
||||
await invite_user(username);
|
||||
// console.log("room:", room);
|
||||
// const updated_room = await join_room(room);
|
||||
// console.log("updated room:", updated_room);
|
||||
// await change_room(updated_room);
|
||||
invite_user(username);
|
||||
layout.set("room");
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user