added is admin
This commit is contained in:
@@ -32,6 +32,7 @@ export class ChatController {
|
|||||||
new_room.users = room.users;
|
new_room.users = room.users;
|
||||||
if (room.allowed)
|
if (room.allowed)
|
||||||
new_room.allowed = room.allowed;
|
new_room.allowed = room.allowed;
|
||||||
|
|
||||||
return new_room;
|
return new_room;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,6 +85,40 @@ export class ChatController {
|
|||||||
printCaller("- out ");
|
printCaller("- out ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthenticateGuard)
|
||||||
|
@UseGuards(TwoFactorGuard)
|
||||||
|
@Get('isadmin')
|
||||||
|
async isAdmin(@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);
|
||||||
|
|
||||||
|
res.status(HttpStatus.OK).json({ is_admin: is_admin });
|
||||||
|
printCaller("- out ");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
@UseGuards(AuthenticateGuard)
|
||||||
|
@UseGuards(TwoFactorGuard)
|
||||||
|
@Get('isadmin')
|
||||||
|
async isAdmin(@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);
|
||||||
|
|
||||||
|
res.status(HttpStatus.OK).json({ is_admin: is_admin });
|
||||||
|
printCaller("- out ");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
@UseGuards(AuthenticateGuard)
|
@UseGuards(AuthenticateGuard)
|
||||||
@UseGuards(TwoFactorGuard)
|
@UseGuards(TwoFactorGuard)
|
||||||
@Get('current')
|
@Get('current')
|
||||||
|
|||||||
@@ -432,6 +432,8 @@ export class ChatService {
|
|||||||
printCaller("-- in ");
|
printCaller("-- in ");
|
||||||
|
|
||||||
let room_name = await this.getCurrentRoomName(socket.username);
|
let room_name = await this.getCurrentRoomName(socket.username);
|
||||||
|
|
||||||
|
/*
|
||||||
const current_room = await this.getRoomByName(room_name);
|
const current_room = await this.getRoomByName(room_name);
|
||||||
|
|
||||||
if (current_room.protection)
|
if (current_room.protection)
|
||||||
@@ -442,6 +444,7 @@ export class ChatService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
socket.to(socket.room).emit('message', socket.username, message);
|
socket.to(socket.room).emit('message', socket.username, message);
|
||||||
await this.addMessageToRoom(room_name, socket.username, message);
|
await this.addMessageToRoom(room_name, socket.username, message);
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
<script>
|
<script lang="ts">
|
||||||
|
|
||||||
import { layout, current_room } from './Store_chat';
|
import { layout, current_room, settings_user } from './Store_chat';
|
||||||
import { get_room_users, leave_room } from './Request_rooms';
|
import { get_room_users, leave_room, get_is_admin } from './Request_rooms';
|
||||||
import Button from './Element_button.svelte';
|
import Button from './Element_button.svelte';
|
||||||
|
|
||||||
export let back = "";
|
export let back = "";
|
||||||
|
|
||||||
let users = get_room_users();
|
let users = get_room_users();
|
||||||
|
let is_admin = false;
|
||||||
|
get_is_admin().then(response => is_admin = response);
|
||||||
|
|
||||||
console.log("current_room:", $current_room);
|
console.log("current_room:", $current_room);
|
||||||
|
|
||||||
function user_profile()
|
function user_profile(username: string)
|
||||||
{
|
{
|
||||||
console.log("in user_profile");
|
console.log("in user_profile");
|
||||||
|
settings_user.set(username);
|
||||||
|
layout.set("user");
|
||||||
}
|
}
|
||||||
|
|
||||||
function user_leave_room()
|
function user_leave_room()
|
||||||
@@ -51,6 +55,7 @@
|
|||||||
invite someone
|
invite someone
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
|
{#if is_admin === true }
|
||||||
{#if $current_room.protection }
|
{#if $current_room.protection }
|
||||||
<p class="__center">this room is password protected</p>
|
<p class="__center">this room is password protected</p>
|
||||||
<Button new_layout="change_password">
|
<Button new_layout="change_password">
|
||||||
@@ -64,6 +69,7 @@
|
|||||||
add password
|
add password
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
|
{/if}
|
||||||
<p>room users :</p>
|
<p>room users :</p>
|
||||||
<div class="room_users">
|
<div class="room_users">
|
||||||
<div class="__show_if_only_child">
|
<div class="__show_if_only_child">
|
||||||
@@ -73,7 +79,7 @@
|
|||||||
<p>list of users is loading...</p>
|
<p>list of users is loading...</p>
|
||||||
{:then users}
|
{:then users}
|
||||||
{#each users as user}
|
{#each users as user}
|
||||||
<Button new_layout="user" my_class="list" on:click={user_profile}>
|
<Button my_class="list" on:click={function(){user_profile(user)}}>
|
||||||
{user}
|
{user}
|
||||||
</Button>
|
</Button>
|
||||||
{/each}
|
{/each}
|
||||||
|
|||||||
@@ -1,19 +1,23 @@
|
|||||||
<script>
|
<script>
|
||||||
|
|
||||||
import { layout } from './Store_chat';
|
import { layout, current_room, settings_user } from './Store_chat';
|
||||||
|
import { get_is_admin } from './Request_rooms';
|
||||||
import Button from './Element_button.svelte';
|
import Button from './Element_button.svelte';
|
||||||
|
import { push } from "svelte-spa-router";
|
||||||
|
import { invited_username } from '../store_invitation';
|
||||||
|
|
||||||
export let back = "";
|
export let back = "";
|
||||||
|
|
||||||
let mute = "mute";
|
let mute = "mute";
|
||||||
let block = "block";
|
let block = "block";
|
||||||
|
|
||||||
import { push } from "svelte-spa-router";
|
let is_admin = false;
|
||||||
import { invited_username } from '../store_invitation';
|
get_is_admin().then(response => is_admin = response);
|
||||||
|
|
||||||
function game_invitation()
|
function game_invitation()
|
||||||
{
|
{
|
||||||
const usernamePLACEHOLDER = "hulamy";
|
const username = $settings_user;
|
||||||
invited_username.set(usernamePLACEHOLDER);
|
invited_username.set(username);
|
||||||
push("/game");
|
push("/game");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,7 +32,7 @@
|
|||||||
|
|
||||||
<!-- user -->
|
<!-- user -->
|
||||||
<Button my_class="user deactivate">
|
<Button my_class="user deactivate">
|
||||||
<user>
|
{$settings_user}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<!-- close -->
|
<!-- close -->
|
||||||
@@ -39,7 +43,7 @@
|
|||||||
<!-- room_name -->
|
<!-- room_name -->
|
||||||
{#if back === "room_set"}
|
{#if back === "room_set"}
|
||||||
<Button my_class="room_name deactivate __border_top">
|
<Button my_class="room_name deactivate __border_top">
|
||||||
<room_name>
|
{$current_room.name}
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
@@ -49,7 +53,7 @@
|
|||||||
<Button>
|
<Button>
|
||||||
view profile
|
view profile
|
||||||
</Button>
|
</Button>
|
||||||
<Button on_click={() => game_invitation()}>
|
<Button on:click={game_invitation}>
|
||||||
game invitation
|
game invitation
|
||||||
</Button>
|
</Button>
|
||||||
<Button>
|
<Button>
|
||||||
|
|||||||
@@ -157,10 +157,20 @@ export async function get_all_users()
|
|||||||
return response.users;
|
return response.users;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function leave_room()
|
export async function leave_room(): Promise<void>
|
||||||
{
|
{
|
||||||
console.log("in leave_room");
|
console.log("in leave_room");
|
||||||
|
|
||||||
let response: FetchResponse = await fetch_chat_request('leave', FetchMethod.DELETE);
|
let response: FetchResponse = await fetch_chat_request('leave', FetchMethod.DELETE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function get_is_admin(): Promise<boolean>
|
||||||
|
{
|
||||||
|
console.log("in is_admin");
|
||||||
|
|
||||||
|
let response: FetchResponse = await fetch_chat_request('isadmin', FetchMethod.GET);
|
||||||
|
console.log("is_admin return:", response.is_admin);
|
||||||
|
|
||||||
|
return response.is_admin;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ export let current_room = writable({
|
|||||||
type: "",
|
type: "",
|
||||||
protection: false,
|
protection: false,
|
||||||
});
|
});
|
||||||
|
export let settings_user = writable("");
|
||||||
|
|
||||||
export let user;
|
export let user;
|
||||||
export let socket;
|
export let socket;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ export interface FetchResponse
|
|||||||
users?: string[];
|
users?: string[];
|
||||||
room?: Room;
|
room?: Room;
|
||||||
rooms?: Room[];
|
rooms?: Room[];
|
||||||
|
is_admin?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FetchInit
|
export interface FetchInit
|
||||||
|
|||||||
Reference in New Issue
Block a user