fixed a mutitudes of errors in chat
This commit is contained in:
@@ -97,7 +97,7 @@ export class ChatController {
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Get('currentroom')
|
||||
async getCurrentRooms(@Req() req, @Res() res): Promise<void>
|
||||
async getCurrentRoom(@Req() req, @Res() res): Promise<void>
|
||||
{
|
||||
printCaller("- in ");
|
||||
|
||||
@@ -572,6 +572,42 @@ export class ChatController {
|
||||
printCaller("- out ");
|
||||
}
|
||||
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Post('userinfos')
|
||||
async getUserInfos(@Body('username') username: string, @Req() req, @Res() res): Promise<void>
|
||||
{
|
||||
printCaller("- in ");
|
||||
|
||||
const room_name = await this.chatService.getCurrentRoomName(username);
|
||||
if (!room_name)
|
||||
{
|
||||
console.log("throw error: error: true, code: 'CURRENT_ROOM_NAME_NOT_FOUND', message: 'current_room_name_not_found'");
|
||||
throw new HttpException({ error: true, code: 'CURRENT_ROOM_NAME_NOT_FOUND', message: `current_room_name_not_found` }, HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
const current_room = await this.chatService.getRoomByName(room_name);
|
||||
if (!current_room)
|
||||
{
|
||||
console.log("throw error: error: true, code: 'CURRENT_ROOM_NOT_FOUND', message: 'current_room_not_found'");
|
||||
throw new HttpException({ error: true, code: 'CURRENT_ROOM_NOT_FOUND', message: `current_room_not_found` }, HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
const blocked = await this.chatService.getListBlockUser(req.user.username);
|
||||
const mute = await this.chatService.getUserMute(req.user.username, username);
|
||||
|
||||
let user: any = { name: username, ismute: false, mute_date: null };
|
||||
user.isadmin = current_room.admins.includes(username);
|
||||
if (blocked)
|
||||
user.isblocked = blocked.includes(username);
|
||||
if (mute && mute.name === username)
|
||||
{
|
||||
user.ismute = true;
|
||||
user.mute_date = mute.date;
|
||||
}
|
||||
|
||||
res.status(HttpStatus.OK).json({ user: user });
|
||||
printCaller("- out ");
|
||||
}
|
||||
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Post('setmute')
|
||||
@@ -583,6 +619,7 @@ export class ChatController {
|
||||
await this.chatService.addMute(req.user.username, room_name, mute);
|
||||
|
||||
// inform other connected users
|
||||
console.log("mute object:", mute);
|
||||
let message = `${req.user.username} has muted ${mute.name} untill ${time}`;
|
||||
let socket: socketDto = this.chatService.getSocket(req.user.username);
|
||||
let server = this.chatGateway.server;
|
||||
@@ -598,7 +635,7 @@ export class ChatController {
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Post('ismute')
|
||||
async isuserMute(@Body('username') username: string, @Req() req, @Res() res): Promise<void>
|
||||
async isUserMute(@Body('username') username: string, @Req() req, @Res() res): Promise<void>
|
||||
{
|
||||
printCaller("- in ");
|
||||
|
||||
@@ -618,6 +655,11 @@ export class ChatController {
|
||||
printCaller("- in ");
|
||||
|
||||
const room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
||||
if (!room_name)
|
||||
{
|
||||
console.log("throw error: error: true, code: 'CURRENT_ROOM_NOT_FOUND', message: 'current_room_not_found'");
|
||||
throw new HttpException({ error: true, code: 'CURRENT_ROOM_NOT_FOUND', message: `current_room_not_found` }, HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
const fields = ["admins"];
|
||||
const room_db = await this.chatService.getRoomByName(room_name, fields);
|
||||
|
||||
@@ -285,6 +285,18 @@ export class ChatService {
|
||||
}
|
||||
}
|
||||
|
||||
async getUserMute(current_username: string, username: string, ): Promise<muteDto>
|
||||
{
|
||||
printCaller("- in ");
|
||||
|
||||
const room_name = await this.getCurrentRoomName(current_username);
|
||||
const current_room = await this.getRoomByName(room_name);
|
||||
let mute = current_room.mutes.find(mute => mute.name === username);
|
||||
|
||||
printCaller("- out ");
|
||||
return mute;
|
||||
}
|
||||
|
||||
|
||||
/* SETTERS ************************************************
|
||||
*/
|
||||
@@ -447,8 +459,8 @@ export class ChatService {
|
||||
const room_db = await this.getRoomByName(room_name);
|
||||
if (!room_db)
|
||||
{
|
||||
printCallerError(`ERROR in chat: room ${room_name} not found`);
|
||||
return;
|
||||
printCaller(`throw error: error: true, code: 'ROOM_NOT_FOUND', message: 'room ${room_name} not found'`);
|
||||
throw new HttpException({ error: true, code: 'ROOM_NOT_FOUND', message: `room ${room_name} not found` }, HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
if (room_db.type === "direct")
|
||||
{
|
||||
@@ -460,6 +472,11 @@ export class ChatService {
|
||||
printCaller(`throw error: error: true, code: 'NOT_ADMIN', message: 'you cannot set someone else as admin, since you are not admin yourself'`);
|
||||
throw new HttpException({ error: true, code: 'NOT_ADMIN', message: `you cannot set someone else as admin, since you are not admin yourself` }, HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
if (room_db.admins.includes(user_username))
|
||||
{
|
||||
printCaller(`throw error: error: true, code: 'ALREADY_ADMIN', message: 'this user is already an admin'`);
|
||||
throw new HttpException({ error: true, code: 'ALREADY_ADMIN', message: `this user is already an admin` }, HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
room_db.admins.push(user_username);
|
||||
await this.chatroomRepository.save(room_db);
|
||||
@@ -653,8 +670,8 @@ export class ChatService {
|
||||
const room_db = await this.getRoomByName(room_name);
|
||||
if(!room_db)
|
||||
{
|
||||
printCallerError(`ERROR in chat: room not found for ${username}`);
|
||||
return;
|
||||
console.log("throw error: error: true, code: 'ROOM_NOT_FOUND', message: 'room not found for ${username}'");
|
||||
throw new HttpException({ error: true, code: 'ROOM_NOT_FOUND', message: `room not found for ${username}` }, HttpStatus.FORBIDDEN);
|
||||
}
|
||||
|
||||
if (!room_db.admins.includes(username))
|
||||
@@ -678,6 +695,11 @@ export class ChatService {
|
||||
});
|
||||
if (!already_here)
|
||||
room_db.mutes.push(mute);
|
||||
else
|
||||
{
|
||||
console.log("throw error: error: true, code: 'ALREADY_MUTE', message: 'this user is already mute for this room'");
|
||||
throw new HttpException({ error: true, code: 'ALREADY_MUTE', message: `this user is already mute for this room` }, HttpStatus.FORBIDDEN);
|
||||
}
|
||||
}
|
||||
await this.chatroomRepository.save(room_db);
|
||||
|
||||
@@ -904,9 +926,17 @@ export class ChatService {
|
||||
{
|
||||
printCaller("-- in ");
|
||||
|
||||
socket.leave(socket.room);
|
||||
socket.join(room_name);
|
||||
socket.room = room_name;
|
||||
if (socket)
|
||||
{
|
||||
socket.leave(socket.room);
|
||||
socket.join(room_name);
|
||||
socket.room = room_name;
|
||||
}
|
||||
else
|
||||
{
|
||||
printCaller(`throw error: error: true, code: 'SOCKET_UNDEFINED', message: 'socket_undefined'`);
|
||||
throw new HttpException({ error: true, code: 'SOCKET_UNDEFINED', message: `socket_undefined` }, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
printCaller("-- out ");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user