blocked messages are not in hitory
This commit is contained in:
@@ -225,6 +225,12 @@ export class ChatController {
|
||||
let response = "";
|
||||
if (room.type === 'user')
|
||||
{
|
||||
const blocked = await this.chatService.getListBlockUser(req.user.username);
|
||||
if (blocked.includes(room.name))
|
||||
{
|
||||
console.log("throw error: error: true, code: 'BLOCKED_USER', message: 'you cannot enter this room, you blocked this user'");
|
||||
throw new HttpException({ error: true, code: 'BLOCKED_USER', message: `you cannot enter this room, you blocked this user` }, HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
room.type = 'direct';
|
||||
room.users = [room.name, req.user.username];
|
||||
room.name += ` + ${req.user.username}`;
|
||||
@@ -268,7 +274,7 @@ export class ChatController {
|
||||
{
|
||||
printCaller("- in ");
|
||||
|
||||
let fields = ["protection", "allowed_users"];
|
||||
let fields = ["protection", "allowed_users", "type", "users"];
|
||||
const room_db = await this.chatService.getRoomByName(room.name, fields);
|
||||
|
||||
if (room_db.protection === true)
|
||||
@@ -280,6 +286,19 @@ export class ChatController {
|
||||
}
|
||||
}
|
||||
|
||||
const blocked = await this.chatService.getListBlockUser(req.user.username);
|
||||
if (room_db.type === 'direct')
|
||||
{
|
||||
let roomname = room_db.users[0];
|
||||
if (roomname === req.user.username)
|
||||
roomname = room.users[1];
|
||||
if (blocked.includes(roomname))
|
||||
{
|
||||
console.log("throw error: error: true, code: 'BLOCKED_USER', message: 'you cannot enter this room, you blocked this user'");
|
||||
throw new HttpException({ error: true, code: 'BLOCKED_USER', message: `you cannot enter this room, you blocked this user` }, HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
}
|
||||
|
||||
await this.chatService.setCurrentRoom(req.user.username, room.name);
|
||||
let socket: socketDto = this.chatGateway.sockets.get(req.user.username);
|
||||
await this.chatService.socketChangeRoom(socket, room.name);
|
||||
@@ -386,6 +405,14 @@ export class ChatController {
|
||||
{
|
||||
printCaller("- in ");
|
||||
|
||||
|
||||
const blocked = await this.chatService.getListBlockUser(req.user.username);
|
||||
if (blocked.includes(username))
|
||||
{
|
||||
console.log("throw error: error: true, code: 'BLOCKED_USER', message: 'you cannot invite this user, you have blocked it'");
|
||||
throw new HttpException({ error: true, code: 'BLOCKED_USER', message: `you cannot invite this user, you have blocked it` }, HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
let current_room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
||||
let room = await this.chatService.addUserToRoom(username, current_room_name);
|
||||
let message = `${username} joined the room`;
|
||||
@@ -428,7 +455,17 @@ export class ChatController {
|
||||
printCaller("- in ");
|
||||
|
||||
const messages = await this.chatService.getMessagesFromCurrentRoom(req.user.username);
|
||||
res.status(HttpStatus.OK).json({ messages: messages });
|
||||
|
||||
console.log("messages:", messages);
|
||||
const blocked = await this.chatService.getListBlockUser(req.user.username);
|
||||
let filtered_messages = messages.filter(message =>
|
||||
{
|
||||
if (blocked.includes(message.name))
|
||||
return false;
|
||||
return true;
|
||||
});
|
||||
|
||||
res.status(HttpStatus.OK).json({ messages: filtered_messages });
|
||||
printCaller("- out ");
|
||||
}
|
||||
|
||||
@@ -481,7 +518,15 @@ export class ChatController {
|
||||
const room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
||||
const users = await this.chatService.getAllUsersNotInRoom(room_name);
|
||||
|
||||
res.status(HttpStatus.OK).json({ users: users });
|
||||
const blocked = await this.chatService.getListBlockUser(req.user.username);
|
||||
let filtered_users = users.filter(user =>
|
||||
{
|
||||
if (blocked.includes(user.username))
|
||||
return false;
|
||||
return true;
|
||||
});
|
||||
|
||||
res.status(HttpStatus.OK).json({ users: filtered_users });
|
||||
printCaller("- out ");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user