interaction blocked users and view profile ok, still block message todo
This commit is contained in:
@@ -116,7 +116,7 @@ export class ChatController {
|
|||||||
const room_db = await this.chatService.getRoomByName(room_name, fields);
|
const room_db = await this.chatService.getRoomByName(room_name, fields);
|
||||||
const is_admin = room_db.admins.includes(req.user.username);
|
const is_admin = room_db.admins.includes(req.user.username);
|
||||||
|
|
||||||
res.status(HttpStatus.OK).json({ is_admin: is_admin });
|
res.status(HttpStatus.OK).json({ condition: is_admin });
|
||||||
printCaller("- out ");
|
printCaller("- out ");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -418,6 +418,7 @@ export class ChatController {
|
|||||||
const room = await this.chatService.getRoomByName(room_name);
|
const room = await this.chatService.getRoomByName(room_name);
|
||||||
const users = room.users;
|
const users = room.users;
|
||||||
const admins = room.admins;
|
const admins = room.admins;
|
||||||
|
const blocked = await this.chatService.getListBlockUser(req.user.username);
|
||||||
|
|
||||||
let index = users.indexOf(req.user.username);
|
let index = users.indexOf(req.user.username);
|
||||||
if (index > -1)
|
if (index > -1)
|
||||||
@@ -429,9 +430,13 @@ export class ChatController {
|
|||||||
{
|
{
|
||||||
name: username,
|
name: username,
|
||||||
isadmin: false,
|
isadmin: false,
|
||||||
|
isblocked: false,
|
||||||
};
|
};
|
||||||
if (admins.includes(username))
|
if (admins.includes(username))
|
||||||
new_user.isadmin = true;
|
new_user.isadmin = true;
|
||||||
|
if (blocked.includes(username))
|
||||||
|
new_user.isblocked = true;
|
||||||
|
console.log("new_user:", new_user);
|
||||||
|
|
||||||
return new_user;
|
return new_user;
|
||||||
});
|
});
|
||||||
@@ -532,7 +537,8 @@ export class ChatController {
|
|||||||
{
|
{
|
||||||
printCaller("- in ");
|
printCaller("- in ");
|
||||||
|
|
||||||
await this.chatService.setBlockUser(req.user.username, username);
|
await this.chatService.addBlockUser(req.user.username, username);
|
||||||
|
|
||||||
let user_socket: socketDto = this.chatGateway.sockets.get(req.user.username);
|
let user_socket: socketDto = this.chatGateway.sockets.get(req.user.username);
|
||||||
user_socket.join(`${username}_not_emit`);
|
user_socket.join(`${username}_not_emit`);
|
||||||
|
|
||||||
@@ -547,6 +553,7 @@ export class ChatController {
|
|||||||
{
|
{
|
||||||
printCaller("- in ");
|
printCaller("- in ");
|
||||||
|
|
||||||
|
await this.chatService.removeBlockUser(req.user.username, username);
|
||||||
let user_socket: socketDto = this.chatGateway.sockets.get(req.user.username);
|
let user_socket: socketDto = this.chatGateway.sockets.get(req.user.username);
|
||||||
user_socket.leave(`${username}_not_emit`);
|
user_socket.leave(`${username}_not_emit`);
|
||||||
|
|
||||||
@@ -554,5 +561,26 @@ export class ChatController {
|
|||||||
printCaller("- out ");
|
printCaller("- out ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@UseGuards(AuthenticateGuard)
|
||||||
|
@UseGuards(TwoFactorGuard)
|
||||||
|
@Get('listblock')
|
||||||
|
async listBlockUser(@Req() req, @Res() res): Promise<void>
|
||||||
|
{
|
||||||
|
printCaller("- in ");
|
||||||
|
|
||||||
|
let block_users = await this.chatService.getListBlockUser(req.user.username);
|
||||||
|
let users = block_users.map(user =>
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
name: user,
|
||||||
|
isadmin: false,
|
||||||
|
isblocked: true,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(HttpStatus.OK).json({ users: users });
|
||||||
|
printCaller("- out ");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,14 +3,17 @@ import { ChatController } from './chat.controller';
|
|||||||
import { ChatService } from './chat.service';
|
import { ChatService } from './chat.service';
|
||||||
import { ChatGateway } from './chat.gateway';
|
import { ChatGateway } from './chat.gateway';
|
||||||
import { UsersModule } from 'src/users/users.module';
|
import { UsersModule } from 'src/users/users.module';
|
||||||
|
import { FriendshipsModule } from 'src/friendship/friendships.module';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { Chatroom } from './entities/chatroom.entity';
|
import { Chatroom } from './entities/chatroom.entity';
|
||||||
import { User } from 'src/users/entities/user.entity';
|
import { User } from 'src/users/entities/user.entity';
|
||||||
|
import { Friendship } from 'src/friendship/entities/friendship.entity';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
TypeOrmModule.forFeature([Chatroom, User]),
|
TypeOrmModule.forFeature([Chatroom, User, Friendship]),
|
||||||
UsersModule,
|
UsersModule,
|
||||||
|
FriendshipsModule,
|
||||||
],
|
],
|
||||||
controllers: [
|
controllers: [
|
||||||
ChatController,
|
ChatController,
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
import { HttpException, HttpStatus, Injectable, Res } from '@nestjs/common';
|
import { HttpException, HttpStatus, Injectable, Res } from '@nestjs/common';
|
||||||
import { User } from 'src/users/entities/user.entity';
|
import { User } from 'src/users/entities/user.entity';
|
||||||
import { UsersService } from 'src/users/users.service';
|
import { Friendship, FriendshipStatus } from 'src/friendship/entities/friendship.entity';
|
||||||
import { Chatroom } from './entities/chatroom.entity';
|
import { Chatroom } from './entities/chatroom.entity';
|
||||||
import { Repository } from 'typeorm';
|
import { UsersService } from 'src/users/users.service';
|
||||||
|
import { FriendshipService } from 'src/friendship/friendship.service';
|
||||||
|
import { SendableFriendship } from 'src/friendship/sendableFriendship';
|
||||||
|
import { Repository, Brackets } from 'typeorm';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { roomDto } from './dto/room.dto';
|
import { roomDto } from './dto/room.dto';
|
||||||
import { messagesDto } from './dto/messages.dto';
|
import { messagesDto } from './dto/messages.dto';
|
||||||
@@ -17,10 +20,13 @@ export class ChatService {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private usersService: UsersService,
|
private usersService: UsersService,
|
||||||
|
private friendshipService: FriendshipService,
|
||||||
@InjectRepository(User)
|
@InjectRepository(User)
|
||||||
private readonly userRepository: Repository<User>,
|
private readonly userRepository: Repository<User>,
|
||||||
@InjectRepository(Chatroom)
|
@InjectRepository(Chatroom)
|
||||||
private readonly chatroomRepository: Repository<Chatroom>,
|
private readonly chatroomRepository: Repository<Chatroom>,
|
||||||
|
@InjectRepository(Friendship)
|
||||||
|
private readonly friendshipRepository: Repository<Friendship>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
// temp for test
|
// temp for test
|
||||||
@@ -298,14 +304,111 @@ export class ChatService {
|
|||||||
printCaller("-- out ");
|
printCaller("-- out ");
|
||||||
}
|
}
|
||||||
|
|
||||||
async setBlockUser(username: string, to_block_username: string): Promise<void>
|
async findOneRelationshipByUsername(friendUsername : string, username : string)
|
||||||
|
{
|
||||||
|
const friendship = await this.friendshipRepository
|
||||||
|
.createQueryBuilder('friendship')
|
||||||
|
.leftJoinAndSelect('friendship.sender', 'sender')
|
||||||
|
.leftJoinAndSelect('friendship.receiver', 'receiver')
|
||||||
|
.where
|
||||||
|
(
|
||||||
|
new Brackets((qb) =>
|
||||||
|
{
|
||||||
|
qb.where
|
||||||
|
(
|
||||||
|
new Brackets((subAQb) =>
|
||||||
|
{
|
||||||
|
subAQb.where('sender.username = :username', {username : username})
|
||||||
|
.andWhere('receiver.username = :friendUsername', {friendUsername : friendUsername})
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.orWhere
|
||||||
|
(
|
||||||
|
new Brackets((subBQb) =>
|
||||||
|
{
|
||||||
|
subBQb.where('sender.username = :friendUsername2', {friendUsername2 : friendUsername})
|
||||||
|
.andWhere('receiver.username = :username2', {username2 : username})
|
||||||
|
.andWhere('friendship.status != :status', {status : FriendshipStatus.BLOCKED})
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.getOne()
|
||||||
|
|
||||||
|
if (!friendship)
|
||||||
|
return null;
|
||||||
|
return new SendableFriendship(friendship);
|
||||||
|
}
|
||||||
|
|
||||||
|
async addBlockUser(username: string, to_block_username: string): Promise<void>
|
||||||
{
|
{
|
||||||
printCaller("-- in ");
|
printCaller("-- in ");
|
||||||
|
|
||||||
|
let user = await this.getUserByName(username);
|
||||||
|
let relation = await this.findOneRelationshipByUsername(to_block_username, username);
|
||||||
|
if (relation)
|
||||||
|
{
|
||||||
|
let blocked_friendship = await this.friendshipService.blockFriendship(relation.id, user);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const newFriendshipDto = {"receiverUsername": to_block_username, "status": FriendshipStatus.BLOCKED};
|
||||||
|
await this.friendshipService.create(newFriendshipDto, user);
|
||||||
|
}
|
||||||
|
|
||||||
printCaller("-- out ");
|
printCaller("-- out ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async removeBlockUser(username: string, to_unblock_username: string): Promise<void>
|
||||||
|
{
|
||||||
|
printCaller("-- in ");
|
||||||
|
|
||||||
|
let user = await this.getUserByName(username);
|
||||||
|
let relation = await this.findOneRelationshipByUsername(to_unblock_username, username);
|
||||||
|
await this.friendshipService.removeFriendship(relation.id, user);
|
||||||
|
|
||||||
|
printCaller("-- out ");
|
||||||
|
}
|
||||||
|
|
||||||
|
async getListBlockUser(username: string): Promise<string[]>
|
||||||
|
{
|
||||||
|
printCaller("-- in ");
|
||||||
|
|
||||||
|
let user = await this.getUserByName(username);
|
||||||
|
let friends_users = await this.friendshipService.findAllBlockedFriends(user.id);
|
||||||
|
let users = friends_users.map(user => user.receiverUsername);
|
||||||
|
console.log(users);
|
||||||
|
|
||||||
|
printCaller("-- out ");
|
||||||
|
return users;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
// find list blocked
|
||||||
|
|
||||||
|
findAllBlockedFriends
|
||||||
|
extract the receiver_username (i am the sender)
|
||||||
|
|
||||||
|
|
||||||
|
// bock a user
|
||||||
|
|
||||||
|
findfriendshipbyname
|
||||||
|
return friendship
|
||||||
|
blockfriendship
|
||||||
|
return nothing
|
||||||
|
createfriendship
|
||||||
|
return friendship (it worked)
|
||||||
|
return http exception (cannot create friendship)
|
||||||
|
|
||||||
|
|
||||||
|
// unblock
|
||||||
|
|
||||||
|
findfriendshipbyname
|
||||||
|
return friendship
|
||||||
|
removefriendship
|
||||||
|
return nothing
|
||||||
|
*/
|
||||||
|
|
||||||
/* ADDERS *************************************************
|
/* ADDERS *************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,4 @@ export class User {
|
|||||||
|
|
||||||
@Column({ nullable: true })
|
@Column({ nullable: true })
|
||||||
currentRoom: string; // chatroom name
|
currentRoom: string; // chatroom name
|
||||||
|
|
||||||
@Column("simple-array", { nullable: true })
|
|
||||||
blockedUsers: string[]; // usernames
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
lines_width: "1px",
|
lines_width: "1px",
|
||||||
lines_color: "rgb(30, 30, 30)",
|
lines_color: "rgb(30, 30, 30)",
|
||||||
lines_light_color: "rgb(70, 70, 70)",
|
lines_light_color: "rgb(70, 70, 70)",
|
||||||
bg_color: "rgb(251, 156, 81)",
|
bg_color: "rgb(251, 139, 36)",
|
||||||
bg_light_color: "rgb(251, 156, 81)",
|
bg_light_color: "rgb(251, 156, 81)",
|
||||||
|
|
||||||
btn_color: "rgb(220, 220, 220)",
|
btn_color: "rgb(220, 220, 220)",
|
||||||
@@ -28,6 +28,8 @@
|
|||||||
chat_other_color: "rgb(250, 250, 250)",
|
chat_other_color: "rgb(250, 250, 250)",
|
||||||
chat_other_bg_color: "rgb(190, 130, 70)",
|
chat_other_bg_color: "rgb(190, 130, 70)",
|
||||||
chat_serveur_color: "rgb(110, 110, 110)",
|
chat_serveur_color: "rgb(110, 110, 110)",
|
||||||
|
chat_msg_bg_color: "rgb(251, 163, 80)",
|
||||||
|
chat_conv_bg_color: "rgb(251, 163, 80)",
|
||||||
}
|
}
|
||||||
let style_dark =
|
let style_dark =
|
||||||
{
|
{
|
||||||
@@ -53,6 +55,8 @@
|
|||||||
chat_other_color: "rgb( 90, 90, 90)",
|
chat_other_color: "rgb( 90, 90, 90)",
|
||||||
chat_other_bg_color: "rgb(210, 210, 210)",
|
chat_other_bg_color: "rgb(210, 210, 210)",
|
||||||
chat_serveur_color: "rgb(190, 190, 190)",
|
chat_serveur_color: "rgb(190, 190, 190)",
|
||||||
|
chat_msg_bg_color: "rgb( 82, 82, 82)",
|
||||||
|
chat_conv_bg_color: "rgb( 82, 82, 82)",
|
||||||
}
|
}
|
||||||
|
|
||||||
let style = style_light;
|
let style = style_light;
|
||||||
@@ -102,6 +106,8 @@
|
|||||||
--chat_other_color={style.chat_other_color}
|
--chat_other_color={style.chat_other_color}
|
||||||
--chat_other_bg_color={style.chat_other_bg_color}
|
--chat_other_bg_color={style.chat_other_bg_color}
|
||||||
--chat_serveur_color={style.chat_serveur_color}
|
--chat_serveur_color={style.chat_serveur_color}
|
||||||
|
--chat_msg_bg_color={style.chat_msg_bg_color}
|
||||||
|
--chat_conv_bg_color={style.chat_conv_bg_color}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|||||||
@@ -111,7 +111,7 @@
|
|||||||
|
|
||||||
overflow-x: hidden;
|
overflow-x: hidden;
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
background-color: var(--bg_color);
|
background-color: var(--chat_msg_bg_color);
|
||||||
border: var(--lines_width) solid var(--lines_color);
|
border: var(--lines_width) solid var(--lines_color);
|
||||||
}
|
}
|
||||||
.grid_box .text_area {
|
.grid_box .text_area {
|
||||||
@@ -132,6 +132,7 @@
|
|||||||
.grid_box .panel_msg {
|
.grid_box .panel_msg {
|
||||||
flex-direction: column-reverse;
|
flex-direction: column-reverse;
|
||||||
border: var(--lines_width) solid var(--lines_color);
|
border: var(--lines_width) solid var(--lines_color);
|
||||||
|
background-color: var(--chat_conv_bg_color);
|
||||||
}
|
}
|
||||||
.grid_box .msg_thread {
|
.grid_box .msg_thread {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|||||||
@@ -9,15 +9,16 @@
|
|||||||
export let back = "";
|
export let back = "";
|
||||||
|
|
||||||
let users: User[] = get_room_users();
|
let users: User[] = get_room_users();
|
||||||
|
|
||||||
let is_admin = false;
|
let is_admin = false;
|
||||||
get_is_admin().then(response => is_admin = response);
|
get_is_admin().then(response => is_admin = response);
|
||||||
|
|
||||||
to_print("current_room:", $current_room);
|
to_print("current_room:", $current_room);
|
||||||
|
|
||||||
function user_profile(username: string)
|
function user_profile(room_user: string)
|
||||||
{
|
{
|
||||||
to_print("in user_profile");
|
to_print("in user_profile");
|
||||||
settings_user.set(username);
|
settings_user.set(room_user);
|
||||||
layout.set("user");
|
layout.set("user");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +83,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 my_class="list admin" on:click={function(){user_profile(user.name)}}>
|
<Button my_class="list admin {user.isblocked ? 'blocked' : ''}" on:click={function(){user_profile(user)}}>
|
||||||
{user.name}
|
{user.name}
|
||||||
{#if user.isadmin }
|
{#if user.isadmin }
|
||||||
<span>admin</span>
|
<span>admin</span>
|
||||||
|
|||||||
@@ -1,10 +1,22 @@
|
|||||||
<script>
|
<script lang="ts">
|
||||||
|
|
||||||
import { layout } from './Store_chat';
|
import { layout, settings_user } from './Store_chat';
|
||||||
|
import { list_block_user } from './Request_rooms';
|
||||||
|
import { User } from './Types_chat';
|
||||||
|
import { to_print } from './Utils_chat';
|
||||||
import Button from './Element_button.svelte';
|
import Button from './Element_button.svelte';
|
||||||
|
|
||||||
export let back = "";
|
export let back = "";
|
||||||
|
|
||||||
|
let users: User[] = list_block_user();
|
||||||
|
|
||||||
|
function user_profile(room_user: string)
|
||||||
|
{
|
||||||
|
to_print("in user_profile");
|
||||||
|
settings_user.set(room_user);
|
||||||
|
layout.set("user");
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="grid_box">
|
<div class="grid_box">
|
||||||
@@ -31,21 +43,15 @@
|
|||||||
<div class="__show_if_only_child">
|
<div class="__show_if_only_child">
|
||||||
<p class="__center">/ you have blocked no one /</p>
|
<p class="__center">/ you have blocked no one /</p>
|
||||||
</div>
|
</div>
|
||||||
<!-- placeholders
|
{#await users}
|
||||||
<Button bind:layout new_layout="user" my_class="list blocked">
|
<p>list of users is loading...</p>
|
||||||
user 1
|
{:then users}
|
||||||
</Button>
|
{#each users as user}
|
||||||
<Button bind:layout new_layout="user" my_class="list blocked">
|
<Button my_class="list blocked" on:click={function(){user_profile(user)}}>
|
||||||
user 2
|
{user.name}
|
||||||
</Button>
|
</Button>
|
||||||
<Button bind:layout new_layout="user" my_class="list blocked">
|
{/each}
|
||||||
user 3
|
{/await}
|
||||||
</Button>
|
|
||||||
<Button bind:layout new_layout="user" my_class="list blocked">
|
|
||||||
user 4
|
|
||||||
</Button>
|
|
||||||
------------- -->
|
|
||||||
<!-- END placeholders -->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -11,9 +11,6 @@
|
|||||||
|
|
||||||
export let back = "";
|
export let back = "";
|
||||||
|
|
||||||
let mute = "mute";
|
|
||||||
let block = "block";
|
|
||||||
|
|
||||||
let is_admin = false;
|
let is_admin = false;
|
||||||
get_is_admin().then(response => is_admin = response);
|
get_is_admin().then(response => is_admin = response);
|
||||||
|
|
||||||
@@ -23,30 +20,36 @@
|
|||||||
function game_invitation()
|
function game_invitation()
|
||||||
{
|
{
|
||||||
to_print("in game_invitation");
|
to_print("in game_invitation");
|
||||||
const username = $settings_user;
|
const username = $settings_user.name;
|
||||||
invited_username.set(username);
|
invited_username.set(username);
|
||||||
push("/game");
|
push("/game");
|
||||||
}
|
}
|
||||||
function view_profile()
|
function view_profile()
|
||||||
{
|
{
|
||||||
to_print("in view_profile");
|
to_print("in view_profile");
|
||||||
|
push(`/profile/users/${$settings_user.name}`);
|
||||||
}
|
}
|
||||||
async function block_user()
|
async function block_user()
|
||||||
{
|
{
|
||||||
to_print("in block_user");
|
to_print("in block_user");
|
||||||
await set_block_user($settings_user);
|
await set_block_user($settings_user.name);
|
||||||
layout.set("room");
|
layout.set("room");
|
||||||
}
|
}
|
||||||
async function unblock_user()
|
async function unblock_user()
|
||||||
{
|
{
|
||||||
to_print("in unblock_user");
|
to_print("in unblock_user");
|
||||||
await remove_block_user($settings_user);
|
await remove_block_user($settings_user.name);
|
||||||
layout.set("room");
|
layout.set("room");
|
||||||
}
|
}
|
||||||
|
async function get_list_block_user()
|
||||||
|
{
|
||||||
|
to_print("in get_list_block_user");
|
||||||
|
await list_block_user();
|
||||||
|
}
|
||||||
async function make_user_admin()
|
async function make_user_admin()
|
||||||
{
|
{
|
||||||
to_print("in make_user_admin");
|
to_print("in make_user_admin");
|
||||||
response = await make_admin($settings_user);
|
response = await make_admin($settings_user.name);
|
||||||
//show errors
|
//show errors
|
||||||
if (response.status >= 300 || response.error)
|
if (response.status >= 300 || response.error)
|
||||||
show_error = response.error;
|
show_error = response.error;
|
||||||
@@ -64,7 +67,7 @@
|
|||||||
|
|
||||||
<!-- user -->
|
<!-- user -->
|
||||||
<Button my_class="user deactivate">
|
<Button my_class="user deactivate">
|
||||||
{$settings_user}
|
{$settings_user.name}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<!-- close -->
|
<!-- close -->
|
||||||
@@ -91,19 +94,22 @@
|
|||||||
<Button on:click={game_invitation}>
|
<Button on:click={game_invitation}>
|
||||||
game invitation
|
game invitation
|
||||||
</Button>
|
</Button>
|
||||||
<Button on:click={block_user}>
|
{#if $settings_user.isblocked}
|
||||||
block
|
<Button on:click={unblock_user}>
|
||||||
</Button>
|
unblock
|
||||||
<Button on:click={unblock_user}>
|
</Button>
|
||||||
unblock
|
{:else}
|
||||||
</Button>
|
<Button on:click={block_user}>
|
||||||
|
block
|
||||||
|
</Button>
|
||||||
|
{/if}
|
||||||
|
|
||||||
{#if is_admin && back === "room_set" && $current_room.type !== "direct"}
|
{#if is_admin && back === "room_set" && $current_room.type !== "direct"}
|
||||||
<Button on:click={make_user_admin}>
|
<Button on:click={make_user_admin}>
|
||||||
make admin
|
make admin
|
||||||
</Button>
|
</Button>
|
||||||
<Button new_layout="mute">
|
<Button new_layout="mute">
|
||||||
{mute}
|
mute
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { msgs, user, layout, socket, current_room } from './Store_chat';
|
import { msgs, user, layout, socket, current_room } from './Store_chat';
|
||||||
import type { Room, FetchResponse } from './Types_chat';
|
import type { Room, FetchResponse } from './Types_chat';
|
||||||
import { FetchMethod, Mute } from './Types_chat';
|
import { FetchMethod, Mute, User } from './Types_chat';
|
||||||
import { to_print } from './Utils_chat';
|
import { to_print } from './Utils_chat';
|
||||||
import { fetch_chat_request, set_client_name_on_room, fill_fetch_response } from './Request_utils';
|
import { fetch_chat_request, set_client_name_on_room, fill_fetch_response } from './Request_utils';
|
||||||
|
|
||||||
@@ -27,9 +27,9 @@ export async function create_room(room: Room)
|
|||||||
{
|
{
|
||||||
to_print("in create_room");
|
to_print("in create_room");
|
||||||
|
|
||||||
to_print("room sent to create:", room);
|
to_print("room sent to create:", room);
|
||||||
let response: FetchResponse = await fetch_chat_request('create', FetchMethod.POST, room);
|
let response: FetchResponse = await fetch_chat_request('create', FetchMethod.POST, room);
|
||||||
to_print("room returned from create:", response.room);
|
to_print("room returned from create:", response.room);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
@@ -38,9 +38,9 @@ export async function join_room(room: Room)
|
|||||||
{
|
{
|
||||||
to_print("in join_room");
|
to_print("in join_room");
|
||||||
|
|
||||||
to_print("room sent to join:", room);
|
to_print("room sent to join:", room);
|
||||||
let response: FetchResponse = await fetch_chat_request('join', FetchMethod.POST, room);
|
let response: FetchResponse = await fetch_chat_request('join', FetchMethod.POST, room);
|
||||||
to_print("room returned from join:", response.room);
|
to_print("room returned from join:", response.room);
|
||||||
|
|
||||||
return response.room;
|
return response.room;
|
||||||
}
|
}
|
||||||
@@ -49,9 +49,9 @@ export async function change_room(room: Room)
|
|||||||
{
|
{
|
||||||
to_print("in change_room");
|
to_print("in change_room");
|
||||||
|
|
||||||
to_print("room sent to change:", room);
|
to_print("room sent to change:", room);
|
||||||
let response: FetchResponse = await fetch_chat_request('change', FetchMethod.POST, room);
|
let response: FetchResponse = await fetch_chat_request('change', FetchMethod.POST, room);
|
||||||
to_print("room returned from change:", response.room);
|
to_print("room returned from change:", response.room);
|
||||||
|
|
||||||
await get_room_messages();
|
await get_room_messages();
|
||||||
|
|
||||||
@@ -65,9 +65,9 @@ export async function validate_password(room: Room)
|
|||||||
{
|
{
|
||||||
to_print("in validate_password");
|
to_print("in validate_password");
|
||||||
|
|
||||||
to_print("room sent to validate password:", room);
|
to_print("room sent to validate password:", room);
|
||||||
let response: FetchResponse = await fetch_chat_request('passwordauth', FetchMethod.POST, room);
|
let response: FetchResponse = await fetch_chat_request('passwordauth', FetchMethod.POST, room);
|
||||||
to_print("room returned from validate password:", response.room);
|
to_print("room returned from validate password:", response.room);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
@@ -76,9 +76,9 @@ export async function add_password(room: Room)
|
|||||||
{
|
{
|
||||||
to_print("in add_password");
|
to_print("in add_password");
|
||||||
|
|
||||||
to_print("room sent to add password:", room);
|
to_print("room sent to add password:", room);
|
||||||
let response: FetchResponse = await fetch_chat_request('addpassword', FetchMethod.POST, room);
|
let response: FetchResponse = await fetch_chat_request('addpassword', FetchMethod.POST, room);
|
||||||
to_print("room returned from add password:", response.room);
|
to_print("room returned from add password:", response.room);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
@@ -93,9 +93,9 @@ export async function change_password(room: Room, old_password: string)
|
|||||||
old_password: old_password,
|
old_password: old_password,
|
||||||
}
|
}
|
||||||
|
|
||||||
to_print("room sent to change password:", room);
|
to_print("room sent to change password:", room);
|
||||||
let response: FetchResponse = await fetch_chat_request('changepassword', FetchMethod.POST, request_body);
|
let response: FetchResponse = await fetch_chat_request('changepassword', FetchMethod.POST, request_body);
|
||||||
to_print("room returned from change password:", response.room);
|
to_print("room returned from change password:", response.room);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
@@ -104,9 +104,9 @@ export async function remove_password(room: Room)
|
|||||||
{
|
{
|
||||||
to_print("in send_password");
|
to_print("in send_password");
|
||||||
|
|
||||||
to_print("room sent to remove password:", room);
|
to_print("room sent to remove password:", room);
|
||||||
let response: FetchResponse = await fetch_chat_request('removepassword', FetchMethod.DELETE, room);
|
let response: FetchResponse = await fetch_chat_request('removepassword', FetchMethod.DELETE, room);
|
||||||
to_print("room returned from remove password:", response.room);
|
to_print("room returned from remove password:", response.room);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
@@ -140,11 +140,12 @@ export async function get_all_rooms()
|
|||||||
return response.rooms;
|
return response.rooms;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function get_room_users()
|
export async function get_room_users(): Promise<User[]>
|
||||||
{
|
{
|
||||||
to_print("in get_room_users");
|
to_print("in get_room_users");
|
||||||
|
|
||||||
let response: FetchResponse = await fetch_chat_request('roomusers', FetchMethod.GET);
|
let response: FetchResponse = await fetch_chat_request('roomusers', FetchMethod.GET);
|
||||||
|
to_print("response from get_room_users:", response);
|
||||||
|
|
||||||
return response.users;
|
return response.users;
|
||||||
}
|
}
|
||||||
@@ -169,9 +170,9 @@ export async function make_admin(username): Promise<FetchResponse>
|
|||||||
{
|
{
|
||||||
to_print("in is_admin");
|
to_print("in is_admin");
|
||||||
|
|
||||||
to_print("username sent to setadmin:", username);
|
to_print("username sent to setadmin:", username);
|
||||||
let response: FetchResponse = await fetch_chat_request('setadmin', FetchMethod.POST, {username: username} );
|
let response: FetchResponse = await fetch_chat_request('setadmin', FetchMethod.POST, {username: username} );
|
||||||
to_print("response from setadmin:", response);
|
to_print("response from setadmin:", response);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
@@ -181,9 +182,9 @@ export async function get_is_admin(): Promise<boolean>
|
|||||||
to_print("in is_admin");
|
to_print("in is_admin");
|
||||||
|
|
||||||
let response: FetchResponse = await fetch_chat_request('isadmin', FetchMethod.GET);
|
let response: FetchResponse = await fetch_chat_request('isadmin', FetchMethod.GET);
|
||||||
to_print("is_admin return:", response.is_admin);
|
to_print("is_admin return:", response.condition);
|
||||||
|
|
||||||
return response.is_admin;
|
return response.condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function set_mute(date_limit: Date, username: string, time: string): Promise<FetchResponse>
|
export async function set_mute(date_limit: Date, username: string, time: string): Promise<FetchResponse>
|
||||||
@@ -200,9 +201,9 @@ export async function set_mute(date_limit: Date, username: string, time: string)
|
|||||||
time: time,
|
time: time,
|
||||||
}
|
}
|
||||||
|
|
||||||
to_print("setmute send body:", body);
|
to_print("setmute send body:", body);
|
||||||
let response: FetchResponse = await fetch_chat_request('setmute', FetchMethod.POST, body );
|
let response: FetchResponse = await fetch_chat_request('setmute', FetchMethod.POST, body );
|
||||||
to_print("setmute return:", response);
|
to_print("setmute return:", response);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
@@ -212,7 +213,7 @@ export async function get_is_mute(username: string): Promise<Mute>
|
|||||||
to_print("in get_is_mute");
|
to_print("in get_is_mute");
|
||||||
|
|
||||||
let response: FetchResponse = await fetch_chat_request('ismute', FetchMethod.POST, {username: username} );
|
let response: FetchResponse = await fetch_chat_request('ismute', FetchMethod.POST, {username: username} );
|
||||||
to_print("ismute return:", response);
|
to_print("ismute return:", response);
|
||||||
|
|
||||||
return response.mute;
|
return response.mute;
|
||||||
}
|
}
|
||||||
@@ -238,3 +239,13 @@ export async function remove_block_user(username: string): Promise<void>
|
|||||||
await fetch_chat_request('unblock', FetchMethod.POST, {username: username} );
|
await fetch_chat_request('unblock', FetchMethod.POST, {username: username} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function list_block_user(username: string): Promise<string>
|
||||||
|
{
|
||||||
|
to_print("in list_block_user");
|
||||||
|
|
||||||
|
let response = await fetch_chat_request('listblock', FetchMethod.GET);
|
||||||
|
to_print("response.users:", response.users);
|
||||||
|
|
||||||
|
return response.users;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,12 @@
|
|||||||
import { writable } from 'svelte/store';
|
import { writable } from 'svelte/store';
|
||||||
import type { Room, Message } from './Types_chat';
|
import type { Room, Message, User } from './Types_chat';
|
||||||
|
|
||||||
export let msgs = writable([]);
|
export let msgs = writable<Message[]>();
|
||||||
export let my_rooms = writable([]);
|
export let my_rooms = writable<Room[]>();
|
||||||
export let all_rooms = writable([]);
|
export let all_rooms = writable<Room[]>();
|
||||||
|
export let current_room = writable<Room>();
|
||||||
|
export let settings_user = writable<User>();
|
||||||
export let layout = writable("close");
|
export let layout = writable("close");
|
||||||
export let current_room = writable({
|
|
||||||
name: "",
|
|
||||||
type: "",
|
|
||||||
protection: false,
|
|
||||||
});
|
|
||||||
export let settings_user = writable("");
|
|
||||||
|
|
||||||
export let user;
|
export let user;
|
||||||
export let socket;
|
export let socket;
|
||||||
|
|||||||
@@ -17,13 +17,14 @@ export interface Mute
|
|||||||
export interface Message
|
export interface Message
|
||||||
{
|
{
|
||||||
name: string;
|
name: string;
|
||||||
type: string;
|
message: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface User
|
export interface User
|
||||||
{
|
{
|
||||||
name: string;
|
name: string;
|
||||||
isadmin: boolean;
|
isadmin: boolean;
|
||||||
|
isblocked: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FetchResponse
|
export interface FetchResponse
|
||||||
@@ -36,7 +37,7 @@ export interface FetchResponse
|
|||||||
users?: User[];
|
users?: User[];
|
||||||
room?: Room;
|
room?: Room;
|
||||||
rooms?: Room[];
|
rooms?: Room[];
|
||||||
is_admin?: boolean;
|
condition?: boolean;
|
||||||
mute?: Mute;
|
mute?: Mute;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user