admin messages and not in direct
This commit is contained in:
@@ -95,6 +95,12 @@ export class ChatController {
|
||||
const current_room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
||||
await this.chatService.setAdmin(req.user.username, username, current_room_name);
|
||||
|
||||
let message = `${username} is now admin`;
|
||||
await this.chatService.addMessageToRoom(current_room_name, "SERVER", message);
|
||||
let socket: socketDto = this.chatGateway.sockets.get(req.user.username);
|
||||
let server = this.chatGateway.server;
|
||||
await server.in(socket.room).emit('message', "SERVER", message);
|
||||
|
||||
res.status(HttpStatus.OK).json({ message: `${username} is now admin in room ${current_room_name}` });
|
||||
printCaller("- out ");
|
||||
}
|
||||
|
||||
@@ -280,6 +280,11 @@ export class ChatService {
|
||||
printCaller("-- in ");
|
||||
|
||||
const room_db = await this.getRoomByName(room_name);
|
||||
if (room_db.type === "direct")
|
||||
{
|
||||
printCaller(`throw error: error: true, code: 'NO_DIRECT_ADMIN', message: 'there are no admins in direct messages'`);
|
||||
throw new HttpException({ error: true, code: 'NO_DIRECT_ADMIN', message: `there are no admins in direct messages` }, HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
if (!room_db.admins.includes(current_username))
|
||||
{
|
||||
printCaller(`throw error: error: true, code: 'NOT_ADMIN', message: 'you cannot set someone else as admin, since you are not admin yourself'`);
|
||||
|
||||
Reference in New Issue
Block a user