admin messages and not in direct

This commit is contained in:
simplonco
2023-01-16 00:34:20 +01:00
parent d60f2f0c9f
commit 134fa0fef4
4 changed files with 14 additions and 3 deletions

View File

@@ -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 ");
}

View File

@@ -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'`);

View File

@@ -8,7 +8,7 @@
{
lines_width: "1px",
lines_color: "rgb(30, 30, 30)",
lines_light_color: "rgb(90, 90, 90)",
lines_light_color: "rgb(70, 70, 70)",
bg_color: "bisque",
bg_light_color: "bisque",

View File

@@ -35,10 +35,10 @@
{
to_print("in make_user_admin");
response = await make_admin($settings_user);
//show errors
if (response.status >= 300 || response.error)
show_error = response.error;
layout.set("room");
}
async function ban_mute_user()
{
@@ -84,7 +84,7 @@
game invitation
</Button>
{#if back === "room_set"}
{#if back === "room_set" && $current_room.type !== "direct"}
<Button on:click={make_user_admin}>
make admin
</Button>