mute almost done, still changing layout
This commit is contained in:
@@ -462,8 +462,6 @@ export class ChatController {
|
||||
{
|
||||
printCaller("- in ");
|
||||
|
||||
console.log("mute:", mute);
|
||||
|
||||
const room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
||||
await this.chatService.addMute(req.user.username, room_name, mute);
|
||||
|
||||
@@ -476,11 +474,51 @@ export class ChatController {
|
||||
//await server.to(socket.id).emit('muted');
|
||||
|
||||
const room = await this.chatService.getRoomByName(room_name);
|
||||
console.log("room:", room);
|
||||
|
||||
res.status(HttpStatus.OK).json({ message: message });
|
||||
printCaller("- out ");
|
||||
}
|
||||
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Post('ismute')
|
||||
async isuserMute(@Body('username') username: string, @Req() req, @Res() res): Promise<void>
|
||||
{
|
||||
printCaller("- in ");
|
||||
|
||||
const room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
||||
const current_room = await this.chatService.getRoomByName(room_name);
|
||||
let mute = current_room.mutes.find(mute => mute.name === username);
|
||||
console.log("mute:", mute);
|
||||
console.log("username:", username);
|
||||
|
||||
res.status(HttpStatus.OK).json({ mute: mute });
|
||||
printCaller("- out ");
|
||||
}
|
||||
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Post('unmute')
|
||||
async unMute(@Body('username') username: string, @Req() req, @Res() res): Promise<void>
|
||||
{
|
||||
printCaller("- in ");
|
||||
|
||||
const room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
||||
|
||||
const fields = ["admins"];
|
||||
const room_db = await this.chatService.getRoomByName(room_name, fields);
|
||||
const is_admin = room_db.admins.includes(req.user.username);
|
||||
if (!is_admin)
|
||||
{
|
||||
console.log("throw error: error: true, code: 'UNMUTE_NEED_ADMIN', message: 'you cannot unmute a user if you are not admin in the room'");
|
||||
throw new HttpException({ error: true, code: 'UNMUTE_NEED_ADMIN', message: `you cannot unmute a user if you are not admin in the room` }, HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
await this.chatService.removeMute(username, room_name);
|
||||
|
||||
res.status(HttpStatus.OK).json({ message: "successfull unmute" });
|
||||
printCaller("- out ");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -519,9 +519,13 @@ export class ChatService {
|
||||
let current_mute = current_room.mutes.find(mute => mute.name === socket.username);
|
||||
if (current_mute)
|
||||
{
|
||||
const date_now = new Date();
|
||||
const date_mute = new Date(current_mute.date);
|
||||
const date_diff = date_mute.getTime() - date_now.getTime();
|
||||
let date_diff = 1;
|
||||
if (current_mute.date)
|
||||
{
|
||||
const date_now = new Date();
|
||||
const date_mute = new Date(current_mute.date);
|
||||
date_diff = date_mute.getTime() - date_now.getTime();
|
||||
}
|
||||
if (date_diff > 0)
|
||||
{
|
||||
socket.emit('message', "SERVER", "your message was not sent because you are muted");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IsNotEmpty, IsString, IsDate } from "class-validator";
|
||||
import { IsNotEmpty, IsString, IsDate, IsOptional } from "class-validator";
|
||||
|
||||
export class muteDto
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user