directs have good names and cannot leave server side
This commit is contained in:
@@ -74,11 +74,11 @@
|
||||
- [/] chat in room
|
||||
- [/] join public rooms
|
||||
- [ ] join private rooms
|
||||
- [ ] join direct rooms
|
||||
- [/] join direct rooms
|
||||
- [/] see all joignable rooms
|
||||
- [/] see all my rooms
|
||||
- [/] leave room
|
||||
- [ ] leave direct
|
||||
- [ ] leave direct impossible
|
||||
- [ ] invite someone in room
|
||||
- [ ] make admin
|
||||
- [ ] ban
|
||||
|
||||
@@ -49,7 +49,6 @@ export class ChatController {
|
||||
console.log("- in getAllRooms controller");
|
||||
|
||||
const rooms: roomDto[] = await this.chatService.getAllOtherRoomsAndUsers(req.user.username)
|
||||
console.log("--- rooms:", rooms);
|
||||
res.status(HttpStatus.OK).json({ rooms: rooms });
|
||||
|
||||
console.log("- out getAllRooms controller");
|
||||
@@ -96,6 +95,8 @@ export class ChatController {
|
||||
throw new HttpException(`Your room name can not contains these characters : ${forbidden_chars}`, HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
room.users = [req.user.username];
|
||||
room.owner = req.user.username;
|
||||
await this.chatService.addUserToNewRoom(req.user.username, room);
|
||||
res.status(HttpStatus.OK).json({ room: room });
|
||||
|
||||
@@ -117,13 +118,15 @@ export class ChatController {
|
||||
room.type = 'direct';
|
||||
room.users = [room.name, req.user.username];
|
||||
room.name += ` + ${req.user.username}`;
|
||||
room.owner = req.user.username;
|
||||
await this.chatService.addUserToNewRoom(req.user.username, room);
|
||||
}
|
||||
else
|
||||
await this.chatService.addUserToRoom(req.user.username, room.name);
|
||||
room = await this.chatService.addUserToRoom(req.user.username, room.name);
|
||||
|
||||
let socket: socketDto = this.chatGateway.sockets.get(req.user.username);
|
||||
await this.chatService.socketJoinRoom(socket, room.name);
|
||||
|
||||
res.status(HttpStatus.OK).json({ room: room });
|
||||
|
||||
console.log("- out joinRoom controller");
|
||||
@@ -146,10 +149,15 @@ export class ChatController {
|
||||
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Post('leave')
|
||||
async leaveRoom(@Body() body)
|
||||
@Delete('leave')
|
||||
async leaveRoom(@Req() req, @Res() res): Promise<void>
|
||||
{
|
||||
console.log("- in leaveRoom controller");
|
||||
|
||||
const room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
||||
let response = await this.chatService.removeUserFromRoom(req.user.username, room_name);
|
||||
res.status(HttpStatus.OK).json({ message: response });
|
||||
|
||||
console.log("- out leaveRoom controller");
|
||||
}
|
||||
|
||||
@@ -181,19 +189,5 @@ export class ChatController {
|
||||
console.log("- out getRoomUsers controller");
|
||||
}
|
||||
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Delete('removeuser')
|
||||
async removeUser(@Req() req, @Res() res): Promise<void>
|
||||
{
|
||||
console.log("- in removeUser controller");
|
||||
|
||||
const room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
||||
let response = await this.chatService.removeUserFromRoom(req.user.username, room_name);
|
||||
res.status(HttpStatus.OK).json({ message: response });
|
||||
|
||||
console.log("- out removeUser controller");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ export class ChatService {
|
||||
const rooms = await this.chatroomRepository
|
||||
.createQueryBuilder('chatroom')
|
||||
.where('chatroom.type != :type', { type: 'private' })
|
||||
.andWhere('chatroom.type != :type', { type: 'direct' })
|
||||
.andWhere('chatroom.users NOT LIKE :user_name', { user_name: `%${username}%` })
|
||||
.getMany();
|
||||
console.log("--- rooms:", rooms);
|
||||
@@ -200,17 +201,15 @@ export class ChatService {
|
||||
const newChatroom = new Chatroom();
|
||||
newChatroom.name = room.name;
|
||||
newChatroom.type = room.type;
|
||||
newChatroom.owner = username;
|
||||
newChatroom.users = [username];
|
||||
if (room.type === 'direct')
|
||||
newChatroom.users = room.users;
|
||||
newChatroom.owner = room.owner;
|
||||
newChatroom.users = room.users;
|
||||
newChatroom.messages = [{ name: "SERVER", message: `creation of room ${room.name}` }];
|
||||
await this.chatroomRepository.save(newChatroom);
|
||||
|
||||
console.log("-- out addUserToNewRoom service");
|
||||
}
|
||||
|
||||
async addUserToRoom(username: string, room_name: string): Promise<void>
|
||||
async addUserToRoom(username: string, room_name: string): Promise<roomDto>
|
||||
{
|
||||
console.log("-- in addUserToRoom service");
|
||||
|
||||
@@ -223,6 +222,7 @@ export class ChatService {
|
||||
this.chatroomRepository.save(room);
|
||||
|
||||
console.log("-- out addUserToRoom service");
|
||||
return room;
|
||||
}
|
||||
|
||||
async addMessageToRoom(room_name: string, username: string, message: string): Promise<void>
|
||||
@@ -251,6 +251,8 @@ export class ChatService {
|
||||
const room = await this.getRoomByName(room_name);
|
||||
if (!room.users.includes(username))
|
||||
throw new HttpException(`your are not in this room`, HttpStatus.CONFLICT);
|
||||
if (room.type === "direct")
|
||||
throw new HttpException(`you cannot leave a direct messages conversation`, HttpStatus.CONFLICT);
|
||||
|
||||
// delete user from room
|
||||
room.users.push(username);
|
||||
|
||||
@@ -11,6 +11,14 @@ export class roomDto
|
||||
@IsIn(["public", "protected", "private", "direct", "user"])
|
||||
type: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
owner?: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
client_name?: string;
|
||||
|
||||
@IsArray()
|
||||
@IsString({ each: true })
|
||||
@IsOptional()
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
{:then rooms}
|
||||
{#each rooms as room}
|
||||
<Button my_class="list" on_click={function() {go_to_room(room)}}>
|
||||
{room.name}
|
||||
{room.client_name}
|
||||
</Button>
|
||||
{/each}
|
||||
{/await}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script>
|
||||
|
||||
import { layout, current_room_name } from './Store_chat';
|
||||
import { get_room_users, user_leave_room } from './Request_rooms';
|
||||
import { get_room_users, leave_room } from './Request_rooms';
|
||||
import Button from './Element_button.svelte';
|
||||
|
||||
export let back = "";
|
||||
@@ -13,10 +13,10 @@
|
||||
console/log("in user_profile");
|
||||
}
|
||||
|
||||
function leave_room()
|
||||
function user_leave_room()
|
||||
{
|
||||
console.log("in leave_room");
|
||||
user_leave_room();
|
||||
leave_room();
|
||||
layout.set("home");
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
|
||||
<!-- panel_room_set -->
|
||||
<div class="panel panel_room_set __border_top">
|
||||
<Button on_click={leave_room}>
|
||||
<Button on_click={user_leave_room}>
|
||||
leave
|
||||
</Button>
|
||||
<p>room users :</p>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { msgs, user, layout, socket, current_room_name } from './Store_chat';
|
||||
import { msgs, user, layout, socket, current_room_name, current_room_type } from './Store_chat';
|
||||
import type { Room } from './Interface_chat';
|
||||
|
||||
export async function get_room_messages()
|
||||
@@ -57,6 +57,21 @@ export async function join_room(room: Room)
|
||||
return data.room;
|
||||
}
|
||||
|
||||
function set_client_name_on_room(room: Room)
|
||||
{
|
||||
console.log("in set_client_name_on_room, for room:", room);
|
||||
if (room.type === 'direct')
|
||||
{
|
||||
console.log("in direct room");
|
||||
room.client_name = room.users[0];
|
||||
if (room.client_name === user.username)
|
||||
room.client_name = room.users[1];
|
||||
}
|
||||
else
|
||||
room.client_name = room.name;
|
||||
return room;
|
||||
}
|
||||
|
||||
export async function change_room(room: Room)
|
||||
{
|
||||
console.log("in change_room");
|
||||
@@ -71,14 +86,10 @@ export async function change_room(room: Room)
|
||||
|
||||
await get_room_messages();
|
||||
|
||||
let room_name = data.room.name;
|
||||
if (room.type === 'direct')
|
||||
{
|
||||
room_name === room.users[0];
|
||||
if (room_name === user.username)
|
||||
room_name === room.users[1];
|
||||
}
|
||||
current_room_name.set(room_name);
|
||||
set_client_name_on_room(room);
|
||||
|
||||
current_room_name.set(room.client_name);
|
||||
current_room_type.set(room.type);
|
||||
layout.set("room");
|
||||
}
|
||||
|
||||
@@ -88,9 +99,10 @@ export async function get_my_rooms()
|
||||
|
||||
const response = await fetch('/api/v2/chat/myrooms');
|
||||
const data = await response.json();
|
||||
console.log("data.rooms:", data.rooms);
|
||||
let rooms = data.rooms.map(room => set_client_name_on_room(room));
|
||||
console.log("rooms:", rooms);
|
||||
|
||||
return data.rooms;
|
||||
return rooms;
|
||||
}
|
||||
|
||||
export async function get_all_rooms()
|
||||
@@ -113,11 +125,11 @@ export async function get_room_users()
|
||||
return data.users;
|
||||
}
|
||||
|
||||
export async function user_leave_room()
|
||||
export async function leave_room()
|
||||
{
|
||||
console.log("in leave_room");
|
||||
|
||||
const response = await fetch('/api/v2/chat/removeuser', {
|
||||
const response = await fetch('/api/v2/chat/leave', {
|
||||
method: 'DELETE',
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { writable } from 'svelte/store';
|
||||
export let msgs = writable([]);
|
||||
export let layout = writable("close");
|
||||
export let current_room_name = writable("");
|
||||
export let current_room_type = writable("");
|
||||
|
||||
export let user;
|
||||
export let socket;
|
||||
|
||||
Reference in New Issue
Block a user