creation of directs messages
+ can choose myrooms fields + trying to make type validation without success
This commit is contained in:
5
Makefile
5
Makefile
@@ -24,14 +24,15 @@ destroy:
|
||||
- docker images -aq | xargs --no-run-if-empty docker rmi -f
|
||||
- docker volume ls -q | xargs --no-run-if-empty docker volume rm
|
||||
|
||||
# temp for hugo
|
||||
# temp for hugo, only reinit database
|
||||
db:
|
||||
- docker compose -f postgresql -v down
|
||||
- docker rm -f postgresql
|
||||
- docker rm -f nestjs
|
||||
- docker volume rm -f srcs_data_nest_postgresql
|
||||
docker compose -f ${DOCKERCOMPOSEPATH} up -d --build
|
||||
@make start
|
||||
@docker ps
|
||||
|
||||
|
||||
stop:
|
||||
docker compose -f ${DOCKERCOMPOSEPATH} stop
|
||||
|
||||
@@ -72,10 +72,13 @@
|
||||
- [ ] create private room
|
||||
- [/] create direct room
|
||||
- [/] chat in room
|
||||
- [/] join rooms
|
||||
- [/] join public rooms
|
||||
- [ ] join private rooms
|
||||
- [ ] join direct rooms
|
||||
- [/] see all joignable rooms
|
||||
- [/] see all my rooms
|
||||
- [/] leave room
|
||||
- [ ] leave direct
|
||||
- [ ] invite someone in room
|
||||
- [ ] make admin
|
||||
- [ ] ban
|
||||
|
||||
@@ -35,6 +35,7 @@ RESET="\033[0m"
|
||||
function make_env_for_docker_and_svelte
|
||||
{
|
||||
docker rm -f postgresql
|
||||
docker rm -f nestjs
|
||||
docker volume rm -f srcs_data_nest_postgresql
|
||||
echo -e "${BOLD_BLUE}Creating a new environment for docker${RESET}"
|
||||
NODE_ENV=""
|
||||
|
||||
@@ -4,15 +4,15 @@ import { ConnectedSocket } from '@nestjs/websockets';
|
||||
import { ChatService } from './chat.service';
|
||||
import { User } from 'src/users/entities/user.entity';
|
||||
import { PartialUsersDto } from 'src/users/dto/partial-users.dto';
|
||||
import { createRoomDto } from './dto/createRoom.dto';
|
||||
import { roomDto } from './dto/room.dto';
|
||||
import { setCurrentRoomDto } from './dto/setCurrentRoom.dto';
|
||||
import { ChatGateway } from './chat.gateway';
|
||||
import { socketDto } from './dto/socket.dto';
|
||||
import { Chatroom } from './entities/chatroom.entity';
|
||||
|
||||
@Controller('chat')
|
||||
export class ChatController {
|
||||
|
||||
|
||||
constructor(
|
||||
private chatService: ChatService,
|
||||
private chatGateway: ChatGateway,
|
||||
@@ -32,8 +32,12 @@ export class ChatController {
|
||||
async getMyRooms(@Req() req, @Res() res): Promise<void>
|
||||
{
|
||||
console.log("- in getMyRooms controller");
|
||||
const rooms = await this.chatService.getMyRooms(req.user.username);
|
||||
|
||||
let fields = ["name", "type", "users"];
|
||||
const rooms = await this.chatService.getMyRooms(req.user.username, fields);
|
||||
|
||||
res.status(HttpStatus.OK).json({ rooms: rooms });
|
||||
|
||||
console.log("- out getMyRooms controller");
|
||||
}
|
||||
|
||||
@@ -43,10 +47,11 @@ export class ChatController {
|
||||
async getAllRooms(@Req() req, @Res() res): Promise<void>
|
||||
{
|
||||
console.log("- in getAllRooms controller");
|
||||
const rooms = await this.chatService.getAllOtherRoomsAndUsers(req.user.username)
|
||||
console.log("--- rooms:", rooms);
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
@@ -56,8 +61,10 @@ export class ChatController {
|
||||
async setCurrentRoom(@Body() setCurrentRoomDto: setCurrentRoomDto, @Req() req, @Res() res): Promise<void>
|
||||
{
|
||||
console.log("- in setCurrentRoom controller");
|
||||
|
||||
const response = await this.chatService.setCurrentRoom(req.user.username, setCurrentRoomDto.name);
|
||||
res.status(HttpStatus.OK).json({ message: response });
|
||||
|
||||
console.log("- out setCurrentRoom controller");
|
||||
}
|
||||
|
||||
@@ -67,28 +74,31 @@ export class ChatController {
|
||||
async allowedChars(@Res() res): Promise<void>
|
||||
{
|
||||
console.log("- in allowedChars controller");
|
||||
|
||||
res.status(HttpStatus.OK).json({ chars: this.allowed_chars });
|
||||
|
||||
console.log("- out allowedChars controller");
|
||||
}
|
||||
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Post('create')
|
||||
async createRoom(@Body() createRoomDto: createRoomDto, @Req() req, @Res() res): Promise<void>
|
||||
async createRoom(@Body() room: roomDto, @Req() req, @Res() res): Promise<void>
|
||||
{
|
||||
console.log("- in createRoom controller");
|
||||
|
||||
let chars = this.escape_chars(this.allowed_chars);
|
||||
let regex_base = `[a-zA-Z0-9\\s${chars}]`;
|
||||
let test_regex = new RegExp(`^${regex_base}+$`);
|
||||
if (test_regex.test(createRoomDto.name) === false)
|
||||
if (test_regex.test(room.name) === false)
|
||||
{
|
||||
let forbidden_chars = createRoomDto.name.replace(new RegExp(regex_base, "g"), "");
|
||||
let forbidden_chars = room.name.replace(new RegExp(regex_base, "g"), "");
|
||||
throw new HttpException(`Your room name can not contains these characters : ${forbidden_chars}`, HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
const response = await this.chatService.addUserToNewRoom(req.user.username, createRoomDto);
|
||||
res.status(HttpStatus.OK).json({ room_name: createRoomDto.name, message: response });
|
||||
await this.chatService.addUserToNewRoom(req.user.username, room);
|
||||
res.status(HttpStatus.OK).json({ room: room });
|
||||
|
||||
console.log("- out createRoom controller");
|
||||
}
|
||||
|
||||
@@ -98,6 +108,7 @@ export class ChatController {
|
||||
async joinRoom(@Body() room: roomDto, @Req() req, @Res() res): Promise<void>
|
||||
{
|
||||
console.log("- in joinRoom controller");
|
||||
|
||||
let response = "";
|
||||
if (room.type === 'direct')
|
||||
throw new HttpException(`cannot join a direct messages room`, HttpStatus.CONFLICT);
|
||||
@@ -113,8 +124,8 @@ export class ChatController {
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
@@ -124,12 +135,12 @@ export class ChatController {
|
||||
async changeRoom(@Body() room: roomDto, @Req() req, @Res() res): Promise<void>
|
||||
{
|
||||
console.log("- in changeRoom controller");
|
||||
const response = await this.chatService.setCurrentRoom(req.user.username, room.name);
|
||||
|
||||
const response = await this.chatService.setCurrentRoom(req.user.username, room.name);
|
||||
let socket: socketDto = this.chatGateway.sockets.get(req.user.username);
|
||||
await this.chatService.socketChangeRoom(socket, room.name);
|
||||
|
||||
res.status(HttpStatus.OK).json({ room: room });
|
||||
|
||||
console.log("- out changeRoom controller");
|
||||
}
|
||||
|
||||
@@ -148,8 +159,10 @@ export class ChatController {
|
||||
async getMessages(@Req() req, @Res() res): Promise<void>
|
||||
{
|
||||
console.log("- in getMessages controller");
|
||||
|
||||
const messages = await this.chatService.getMessagesFromCurrentRoom(req.user.username);
|
||||
res.status(HttpStatus.OK).json({ messages: messages });
|
||||
|
||||
console.log("- out getMessages controller");
|
||||
}
|
||||
|
||||
@@ -159,10 +172,12 @@ export class ChatController {
|
||||
async getRoomUsers(@Req() req, @Res() res): Promise<void>
|
||||
{
|
||||
console.log("- in getRoomUsers controller");
|
||||
|
||||
const room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
||||
const room = await this.chatService.getRoomByName(room_name);
|
||||
const users = room.users;
|
||||
res.status(HttpStatus.OK).json({ users: users });
|
||||
|
||||
console.log("- out getRoomUsers controller");
|
||||
}
|
||||
|
||||
@@ -172,9 +187,11 @@ export class ChatController {
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import { UsersService } from 'src/users/users.service';
|
||||
import { Chatroom } from './entities/chatroom.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { createRoomDto } from './dto/createRoom.dto';
|
||||
import { roomDto } from './dto/room.dto';
|
||||
import { messagesDto } from './dto/messages.dto';
|
||||
import { socketDto } from './dto/socket.dto';
|
||||
@@ -21,7 +20,6 @@ export class ChatService {
|
||||
private readonly chatroomRepository: Repository<Chatroom>,
|
||||
) {}
|
||||
|
||||
|
||||
// temp for test
|
||||
sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
@@ -31,13 +29,22 @@ export class ChatService {
|
||||
/* GETTERS ************************************************
|
||||
*/
|
||||
|
||||
async getMyRooms(username: string): Promise<Chatroom[]>
|
||||
async getMyRooms(username: string, fieldsToReturn: string[] = null): Promise<Chatroom[]>
|
||||
{
|
||||
console.log("-- in getMyRooms service");
|
||||
const rooms = await this.chatroomRepository
|
||||
|
||||
const queryBuilder = this.chatroomRepository
|
||||
.createQueryBuilder('chatroom')
|
||||
.where('chatroom.users LIKE :user_name', { user_name: `%${username}%` })
|
||||
.getMany();
|
||||
.where('chatroom.users LIKE :user_name', { user_name: `%${username}%` });
|
||||
|
||||
if (fieldsToReturn)
|
||||
{
|
||||
let fields = fieldsToReturn.map(field => `chatroom.${field}`);
|
||||
queryBuilder.select(fields);
|
||||
}
|
||||
|
||||
const rooms = await queryBuilder.getMany();
|
||||
console.log("--- rooms:", rooms);
|
||||
|
||||
console.log("-- out getMyRooms service");
|
||||
return rooms;
|
||||
@@ -46,6 +53,7 @@ export class ChatService {
|
||||
async getMyDirects(username: string): Promise<Chatroom[]>
|
||||
{
|
||||
console.log("-- in getAllNotMyRooms service");
|
||||
|
||||
const my_rooms = await this.getMyRooms(username);
|
||||
const directs = my_rooms.filter(room => room.type === 'direct');
|
||||
|
||||
@@ -56,9 +64,11 @@ export class ChatService {
|
||||
async getAllRooms(): Promise<Chatroom[]>
|
||||
{
|
||||
console.log("-- in getAllRooms service");
|
||||
|
||||
const rooms = await this.chatroomRepository
|
||||
.createQueryBuilder('chatroom')
|
||||
.getMany();
|
||||
console.log("--- rooms:", rooms);
|
||||
|
||||
console.log("-- out getAllRooms service");
|
||||
return rooms;
|
||||
@@ -67,12 +77,14 @@ export class ChatService {
|
||||
async getAllNotMyRooms(username: string): Promise<Chatroom[]>
|
||||
{
|
||||
console.log("-- in getAllNotMyRooms service");
|
||||
|
||||
const user_db = await this.getUserByName(username);
|
||||
const rooms = await this.chatroomRepository
|
||||
.createQueryBuilder('chatroom')
|
||||
.where('chatroom.type != :type', { type: 'private' })
|
||||
.andWhere('chatroom.users NOT LIKE :user_name', { user_name: `%${username}%` })
|
||||
.getMany();
|
||||
console.log("--- rooms:", rooms);
|
||||
|
||||
console.log("-- out getAllNotMyRooms service");
|
||||
return rooms;
|
||||
@@ -81,11 +93,10 @@ export class ChatService {
|
||||
async getAllOtherRoomsAndUsers(username: string): Promise<roomDto[]>
|
||||
{
|
||||
console.log("-- in getAllOtherRoomsAndUsers service");
|
||||
|
||||
const all_rooms = await this.getAllNotMyRooms(username);
|
||||
const all_users = await this.getAllUsersNotMyRooms(username);
|
||||
|
||||
console.log("--- all_rooms:", all_rooms)
|
||||
console.log("--- all_users:", all_users)
|
||||
let row_rooms = all_rooms.map(room => {
|
||||
return {
|
||||
name: room.name,
|
||||
@@ -99,7 +110,7 @@ export class ChatService {
|
||||
};
|
||||
});
|
||||
let rooms = row_rooms.concat(users);
|
||||
console.log("--- rooms:", rooms)
|
||||
console.log("--- rooms:", rooms);
|
||||
|
||||
console.log("-- in getAllOtherRoomsAndUsers service");
|
||||
return rooms;
|
||||
@@ -108,6 +119,7 @@ export class ChatService {
|
||||
async getMessagesFromCurrentRoom(username: string): Promise<messagesDto[]>
|
||||
{
|
||||
console.log("-- in getMessagesFromCurrentRoom service");
|
||||
|
||||
const user_db = await this.getUserByName(username);
|
||||
const currentRoom = await this.getRoomByName(user_db.currentRoom);
|
||||
let messages = null;
|
||||
@@ -121,7 +133,7 @@ export class ChatService {
|
||||
async getCurrentRoomName(username: string): Promise<string>
|
||||
{
|
||||
console.log("-- in getCurrentRoomName service");
|
||||
console.log('username:', username);
|
||||
|
||||
const user_db = await this.getUserByName(username);
|
||||
|
||||
console.log("-- out getCurrentRoomName service");
|
||||
@@ -131,10 +143,12 @@ export class ChatService {
|
||||
async getRoomByName(room_name: string): Promise<Chatroom>
|
||||
{
|
||||
console.log("-- in getRoomByName service");
|
||||
|
||||
const room = await this.chatroomRepository
|
||||
.createQueryBuilder('chatroom')
|
||||
.where('chatroom.name = :name', { name: room_name.replace("+", "\\+") })
|
||||
.where('chatroom.name = :name', { name: room_name })
|
||||
.getOne();
|
||||
console.log("--- room:", room);
|
||||
|
||||
console.log("-- out getRoomByName service");
|
||||
return room;
|
||||
@@ -143,10 +157,12 @@ export class ChatService {
|
||||
async getRoomById(id: number): Promise<Chatroom>
|
||||
{
|
||||
console.log("-- in getRoomById service");
|
||||
|
||||
const room = await this.chatroomRepository
|
||||
.createQueryBuilder('chatroom')
|
||||
.where('chatroom.id = :id', { id: id })
|
||||
.getOne();
|
||||
console.log("--- room:", room);
|
||||
|
||||
console.log("-- out getRoomById service");
|
||||
return room;
|
||||
@@ -159,6 +175,7 @@ export class ChatService {
|
||||
async setCurrentRoom(username: string, room_name: string): Promise<string>
|
||||
{
|
||||
console.log("-- in setCurrentRoom service");
|
||||
|
||||
const user_db = await this.getUserByName(username);
|
||||
user_db.currentRoom = room_name;
|
||||
this.userRepository.save(user_db);
|
||||
@@ -171,23 +188,24 @@ export class ChatService {
|
||||
/* ADDERS *************************************************
|
||||
*/
|
||||
|
||||
async addUserToNewRoom(username: string, createRoomDto: createRoomDto): Promise<void>
|
||||
async addUserToNewRoom(username: string, room: roomDto): Promise<void>
|
||||
{
|
||||
console.log("-- in addUserToNewRoom service");
|
||||
const room = await this.getRoomByName(createRoomDto.name);
|
||||
if (room)
|
||||
|
||||
const find_room = await this.getRoomByName(room.name);
|
||||
if (find_room)
|
||||
throw new HttpException(`This room name already exist`, HttpStatus.CONFLICT);
|
||||
|
||||
// create chatroom
|
||||
const newChatroom = new Chatroom();
|
||||
newChatroom.name = createRoomDto.name;
|
||||
newChatroom.type = createRoomDto.type;
|
||||
newChatroom.name = room.name;
|
||||
newChatroom.type = room.type;
|
||||
newChatroom.owner = username;
|
||||
newChatroom.users = [username];
|
||||
if (createRoomDto.type === 'direct')
|
||||
newChatroom.users = createRoomDto.users;
|
||||
newChatroom.messages = [{ name: "SERVER", message: `creation of room ${createRoomDto.name}` }];
|
||||
this.chatroomRepository.save(newChatroom);
|
||||
if (room.type === 'direct')
|
||||
newChatroom.users = room.users;
|
||||
newChatroom.messages = [{ name: "SERVER", message: `creation of room ${room.name}` }];
|
||||
await this.chatroomRepository.save(newChatroom);
|
||||
|
||||
console.log("-- out addUserToNewRoom service");
|
||||
}
|
||||
@@ -195,31 +213,30 @@ export class ChatService {
|
||||
async addUserToRoom(username: string, room_name: string): Promise<void>
|
||||
{
|
||||
console.log("-- in addUserToRoom service");
|
||||
|
||||
const room = await this.getRoomByName(room_name);
|
||||
if (room.users.includes(username))
|
||||
throw new HttpException(`your have already join this room`, HttpStatus.CONFLICT);
|
||||
throw new HttpException(`your have already joined this room`, HttpStatus.CONFLICT);
|
||||
|
||||
// update room with new user
|
||||
room.users.push(username);
|
||||
this.chatroomRepository.save(room);
|
||||
|
||||
await this.setCurrentRoom(username, room_name);
|
||||
|
||||
console.log("-- out addUserToRoom service");
|
||||
}
|
||||
|
||||
async addMessageToRoom(room_name: string, username: string, message: string): Promise<void>
|
||||
{
|
||||
console.log("-- in addMessageToRoom service");
|
||||
console.log("--- room_name:", room_name);
|
||||
|
||||
const my_room = await this.getRoomByName(room_name);
|
||||
console.log("--- my_room:", my_room);
|
||||
let chat_message = {
|
||||
name: username,
|
||||
message: message,
|
||||
};
|
||||
my_room.messages.push(chat_message);
|
||||
this.chatroomRepository.save(my_room);
|
||||
|
||||
console.log("-- out addMessageToRoom service");
|
||||
}
|
||||
|
||||
@@ -230,6 +247,7 @@ export class ChatService {
|
||||
async removeUserFromRoom(username: string, room_name: string): Promise<string>
|
||||
{
|
||||
console.log("-- in removeUserFromRoom service");
|
||||
|
||||
const room = await this.getRoomByName(room_name);
|
||||
if (!room.users.includes(username))
|
||||
throw new HttpException(`your are not in this room`, HttpStatus.CONFLICT);
|
||||
@@ -253,10 +271,12 @@ export class ChatService {
|
||||
async getUserByName(username: string): Promise<User>
|
||||
{
|
||||
console.log("-- in getUserByName service");
|
||||
|
||||
const user = await this.userRepository
|
||||
.createQueryBuilder('user')
|
||||
.where('user.username = :name', { name: username })
|
||||
.getOne();
|
||||
console.log("--- user:", user);
|
||||
|
||||
console.log("-- out getUserByName service");
|
||||
return user;
|
||||
@@ -267,7 +287,6 @@ export class ChatService {
|
||||
console.log("-- in getAllUsersNotMyRooms service");
|
||||
|
||||
const directs = await this.getMyDirects(username);
|
||||
console.log("--- directs:", directs);
|
||||
|
||||
// get all users from directs
|
||||
let usernames = directs.map(room => {
|
||||
@@ -277,14 +296,12 @@ export class ChatService {
|
||||
return user;
|
||||
});
|
||||
usernames.push(username);
|
||||
console.log("usernames:", usernames);
|
||||
|
||||
const users = await this.userRepository
|
||||
.createQueryBuilder('user')
|
||||
.where('user.username NOT IN (:...usernames)', { usernames: usernames })
|
||||
.getMany();
|
||||
|
||||
console.log("users:", users);
|
||||
console.log("--- users:", users);
|
||||
|
||||
console.log("-- out getAllUsersNotMyRooms service");
|
||||
return users;
|
||||
@@ -301,6 +318,7 @@ export class ChatService {
|
||||
socket.to(socket.room).emit('message', socket.username, message);
|
||||
let room_name = await this.getCurrentRoomName(socket.username);
|
||||
await this.addMessageToRoom(room_name, socket.username, message);
|
||||
|
||||
console.log("-- out handleSocketIncommingMessage service");
|
||||
}
|
||||
|
||||
@@ -311,6 +329,7 @@ export class ChatService {
|
||||
socket.leave(socket.room);
|
||||
socket.join(room_name);
|
||||
socket.room = room_name;
|
||||
|
||||
console.log('-- out socketChangeRoom service');
|
||||
}
|
||||
|
||||
@@ -324,6 +343,7 @@ export class ChatService {
|
||||
let message = `${socket.username} has join the room`;
|
||||
await socket.to(socket.room).emit('message', "SERVER", message);
|
||||
await this.addMessageToRoom(room_name, "SERVER", message);
|
||||
|
||||
console.log('- out socketJoinRoom service');
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
import { IsString, IsOptional } from "class-validator";
|
||||
import { roomDto } from './room.dto';
|
||||
|
||||
export class createRoomDto extends roomDto
|
||||
{
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
password?: string;
|
||||
}
|
||||
|
||||
@@ -1,22 +1,19 @@
|
||||
import { IsBoolean, IsEmpty, IsInt, IsIn, IsNotEmpty, IsNumber, IsString, IsOptional, IsEnum } from "class-validator";
|
||||
import { Expose } from 'class-transformer';
|
||||
import { IsBoolean, IsEmpty, IsInt, IsIn, IsNotEmpty, IsNumber, IsArray, IsString, IsOptional, IsEnum } from "class-validator";
|
||||
|
||||
export class roomDto
|
||||
{
|
||||
@Expose()
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
name: string;
|
||||
|
||||
@Expose()
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@IsIn(["public", "protected", "private", "direct", "user"])
|
||||
type: string;
|
||||
|
||||
@Expose()
|
||||
@IsString()
|
||||
@IsArray()
|
||||
@IsString({ each: true })
|
||||
@IsOptional()
|
||||
users?: string[];
|
||||
users?: string[]; // usernames
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,23 @@
|
||||
import { Entity, Column, ManyToOne, ManyToMany, JoinTable, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { IsIn } from "class-validator";
|
||||
import { IsBoolean, IsEmpty, IsInt, IsIn, IsNotEmpty, IsNumber, IsArray, IsString, IsOptional, IsEnum } from "class-validator";
|
||||
import { Exclude, Expose } from 'class-transformer';
|
||||
import { User } from 'src/users/entities/user.entity';
|
||||
import { messagesDto } from 'src/chat/dto/messages.dto';
|
||||
|
||||
@Entity('chatroom')
|
||||
export class Chatroom {
|
||||
export class Chatroom
|
||||
{
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
name: string;
|
||||
|
||||
@Column()
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@IsIn(["public", "protected", "private", "direct", "user"])
|
||||
type: string;
|
||||
|
||||
@@ -19,7 +25,10 @@ export class Chatroom {
|
||||
owner: string; // username
|
||||
|
||||
@Column("simple-array")
|
||||
users: string[]; // usernames
|
||||
@IsArray()
|
||||
@IsString({ each: true })
|
||||
@IsOptional()
|
||||
users?: string[]; // usernames
|
||||
|
||||
@Column("json")
|
||||
messages: messagesDto[];
|
||||
|
||||
@@ -3867,27 +3867,21 @@ var app = (function () {
|
||||
});
|
||||
msgs.set(messages);
|
||||
}
|
||||
async function create_room(room_name, room_type) {
|
||||
async function create_room(room) {
|
||||
console.log("in create_room");
|
||||
let form_data = {
|
||||
room_name: room_name,
|
||||
room_type: room_type,
|
||||
};
|
||||
// send the new room
|
||||
const response = await fetch('/api/v2/chat/create', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(form_data),
|
||||
body: JSON.stringify(room),
|
||||
});
|
||||
// get response status and message
|
||||
let response_status = response.status;
|
||||
let data = await response.json();
|
||||
let response_message = "";
|
||||
if (data.message)
|
||||
response_message = data.message;
|
||||
return {
|
||||
status: response_status,
|
||||
message: response_message
|
||||
message: data.message,
|
||||
room: data.room,
|
||||
};
|
||||
}
|
||||
async function join_room(room) {
|
||||
@@ -3902,6 +3896,7 @@ var app = (function () {
|
||||
}
|
||||
async function change_room(room) {
|
||||
console.log("in change_room");
|
||||
console.log("room:", room);
|
||||
const response = await fetch('/api/v2/chat/change', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
@@ -3922,6 +3917,7 @@ var app = (function () {
|
||||
console.log("in get_my_rooms");
|
||||
const response = await fetch('/api/v2/chat/myrooms');
|
||||
const data = await response.json();
|
||||
console.log("data.rooms:", data.rooms);
|
||||
return data.rooms;
|
||||
}
|
||||
async function get_all_rooms() {
|
||||
@@ -3950,11 +3946,11 @@ var app = (function () {
|
||||
|
||||
function get_each_context$8(ctx, list, i) {
|
||||
const child_ctx = ctx.slice();
|
||||
child_ctx[2] = list[i];
|
||||
child_ctx[3] = list[i];
|
||||
return child_ctx;
|
||||
}
|
||||
|
||||
// (23:1) <Button new_layout="settings" my_class="settings dots icon">
|
||||
// (25:1) <Button new_layout="settings" my_class="settings dots icon">
|
||||
function create_default_slot_3$6(ctx) {
|
||||
let t;
|
||||
|
||||
@@ -3974,14 +3970,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot_3$6.name,
|
||||
type: "slot",
|
||||
source: "(23:1) <Button new_layout=\\\"settings\\\" my_class=\\\"settings dots icon\\\">",
|
||||
source: "(25:1) <Button new_layout=\\\"settings\\\" my_class=\\\"settings dots icon\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (28:1) <Button new_layout="new" my_class="new transparent">
|
||||
// (30:1) <Button new_layout="new" my_class="new transparent">
|
||||
function create_default_slot_2$a(ctx) {
|
||||
let t;
|
||||
|
||||
@@ -4001,14 +3997,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot_2$a.name,
|
||||
type: "slot",
|
||||
source: "(28:1) <Button new_layout=\\\"new\\\" my_class=\\\"new transparent\\\">",
|
||||
source: "(30:1) <Button new_layout=\\\"new\\\" my_class=\\\"new transparent\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (33:1) <Button new_layout="close" my_class="close icon">
|
||||
// (35:1) <Button new_layout="close" my_class="close icon">
|
||||
function create_default_slot_1$a(ctx) {
|
||||
let t;
|
||||
|
||||
@@ -4028,7 +4024,7 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot_1$a.name,
|
||||
type: "slot",
|
||||
source: "(33:1) <Button new_layout=\\\"close\\\" my_class=\\\"close icon\\\">",
|
||||
source: "(35:1) <Button new_layout=\\\"close\\\" my_class=\\\"close icon\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
@@ -4057,7 +4053,7 @@ var app = (function () {
|
||||
return block;
|
||||
}
|
||||
|
||||
// (46:3) {:then rooms}
|
||||
// (48:3) {:then rooms}
|
||||
function create_then_block$3(ctx) {
|
||||
let each_1_anchor;
|
||||
let current;
|
||||
@@ -4146,16 +4142,16 @@ var app = (function () {
|
||||
block,
|
||||
id: create_then_block$3.name,
|
||||
type: "then",
|
||||
source: "(46:3) {:then rooms}",
|
||||
source: "(48:3) {:then rooms}",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (48:5) <Button my_class="list" on_click={go_to_room}>
|
||||
// (50:5) <Button my_class="list" on_click={function() {go_to_room(room)}}>
|
||||
function create_default_slot$b(ctx) {
|
||||
let t0_value = /*room*/ ctx[2].name + "";
|
||||
let t0_value = /*room*/ ctx[3].name + "";
|
||||
let t0;
|
||||
let t1;
|
||||
|
||||
@@ -4179,22 +4175,26 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot$b.name,
|
||||
type: "slot",
|
||||
source: "(48:5) <Button my_class=\\\"list\\\" on_click={go_to_room}>",
|
||||
source: "(50:5) <Button my_class=\\\"list\\\" on_click={function() {go_to_room(room)}}>",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (47:4) {#each rooms as room}
|
||||
// (49:4) {#each rooms as room}
|
||||
function create_each_block$8(ctx) {
|
||||
let button;
|
||||
let current;
|
||||
|
||||
function func() {
|
||||
return /*func*/ ctx[2](/*room*/ ctx[3]);
|
||||
}
|
||||
|
||||
button = new Element_button({
|
||||
props: {
|
||||
my_class: "list",
|
||||
on_click: /*go_to_room*/ ctx[0],
|
||||
on_click: func,
|
||||
$$slots: { default: [create_default_slot$b] },
|
||||
$$scope: { ctx }
|
||||
},
|
||||
@@ -4209,10 +4209,11 @@ var app = (function () {
|
||||
mount_component(button, target, anchor);
|
||||
current = true;
|
||||
},
|
||||
p: function update(ctx, dirty) {
|
||||
p: function update(new_ctx, dirty) {
|
||||
ctx = new_ctx;
|
||||
const button_changes = {};
|
||||
|
||||
if (dirty & /*$$scope*/ 32) {
|
||||
if (dirty & /*$$scope*/ 64) {
|
||||
button_changes.$$scope = { dirty, ctx };
|
||||
}
|
||||
|
||||
@@ -4236,14 +4237,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_each_block$8.name,
|
||||
type: "each",
|
||||
source: "(47:4) {#each rooms as room}",
|
||||
source: "(49:4) {#each rooms as room}",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (44:17) <p>rooms are loading...</p> {:then rooms}
|
||||
// (46:17) <p>rooms are loading...</p> {:then rooms}
|
||||
function create_pending_block$3(ctx) {
|
||||
let p;
|
||||
|
||||
@@ -4251,7 +4252,7 @@ var app = (function () {
|
||||
c: function create() {
|
||||
p = element("p");
|
||||
p.textContent = "rooms are loading...";
|
||||
add_location(p, file$q, 44, 4, 1002);
|
||||
add_location(p, file$q, 46, 4, 1018);
|
||||
},
|
||||
m: function mount(target, anchor) {
|
||||
insert_dev(target, p, anchor);
|
||||
@@ -4268,7 +4269,7 @@ var app = (function () {
|
||||
block,
|
||||
id: create_pending_block$3.name,
|
||||
type: "pending",
|
||||
source: "(44:17) <p>rooms are loading...</p> {:then rooms}",
|
||||
source: "(46:17) <p>rooms are loading...</p> {:then rooms}",
|
||||
ctx
|
||||
});
|
||||
|
||||
@@ -4356,17 +4357,17 @@ var app = (function () {
|
||||
t6 = space();
|
||||
info.block.c();
|
||||
attr_dev(p0, "class", "title svelte-1jygwt2");
|
||||
add_location(p0, file$q, 38, 2, 806);
|
||||
add_location(p0, file$q, 40, 2, 822);
|
||||
attr_dev(p1, "class", "__center");
|
||||
add_location(p1, file$q, 41, 4, 916);
|
||||
add_location(p1, file$q, 43, 4, 932);
|
||||
attr_dev(div0, "class", "__show_if_only_child");
|
||||
add_location(div0, file$q, 40, 3, 877);
|
||||
add_location(div0, file$q, 42, 3, 893);
|
||||
attr_dev(div1, "class", "room_list");
|
||||
add_location(div1, file$q, 39, 2, 850);
|
||||
add_location(div1, file$q, 41, 2, 866);
|
||||
attr_dev(div2, "class", "panel panel_home __border_top svelte-1jygwt2");
|
||||
add_location(div2, file$q, 37, 1, 760);
|
||||
add_location(div2, file$q, 39, 1, 776);
|
||||
attr_dev(div3, "class", "grid_box svelte-1jygwt2");
|
||||
add_location(div3, file$q, 19, 0, 437);
|
||||
add_location(div3, file$q, 21, 0, 453);
|
||||
},
|
||||
l: function claim(nodes) {
|
||||
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
|
||||
@@ -4395,21 +4396,21 @@ var app = (function () {
|
||||
ctx = new_ctx;
|
||||
const button0_changes = {};
|
||||
|
||||
if (dirty & /*$$scope*/ 32) {
|
||||
if (dirty & /*$$scope*/ 64) {
|
||||
button0_changes.$$scope = { dirty, ctx };
|
||||
}
|
||||
|
||||
button0.$set(button0_changes);
|
||||
const button1_changes = {};
|
||||
|
||||
if (dirty & /*$$scope*/ 32) {
|
||||
if (dirty & /*$$scope*/ 64) {
|
||||
button1_changes.$$scope = { dirty, ctx };
|
||||
}
|
||||
|
||||
button1.$set(button1_changes);
|
||||
const button2_changes = {};
|
||||
|
||||
if (dirty & /*$$scope*/ 32) {
|
||||
if (dirty & /*$$scope*/ 64) {
|
||||
button2_changes.$$scope = { dirty, ctx };
|
||||
}
|
||||
|
||||
@@ -4464,9 +4465,10 @@ var app = (function () {
|
||||
let rooms = get_my_rooms();
|
||||
|
||||
// go to clicked room
|
||||
async function go_to_room(evt) {
|
||||
async function go_to_room(room) {
|
||||
console.log("inside go_to_room");
|
||||
await change_room(evt.target.innerText);
|
||||
console.log("room:", room);
|
||||
await change_room(room);
|
||||
await get_room_messages();
|
||||
}
|
||||
|
||||
@@ -4476,6 +4478,10 @@ var app = (function () {
|
||||
if (!~writable_props.indexOf(key) && key.slice(0, 2) !== '$$' && key !== 'slot') console_1$d.warn(`<Layout_home> was created with unknown prop '${key}'`);
|
||||
});
|
||||
|
||||
const func = function (room) {
|
||||
go_to_room(room);
|
||||
};
|
||||
|
||||
$$self.$capture_state = () => ({
|
||||
layout,
|
||||
msgs,
|
||||
@@ -4497,7 +4503,7 @@ var app = (function () {
|
||||
$$self.$inject_state($$props.$$inject);
|
||||
}
|
||||
|
||||
return [go_to_room, rooms];
|
||||
return [go_to_room, rooms, func];
|
||||
}
|
||||
|
||||
class Layout_home extends SvelteComponentDev {
|
||||
@@ -5269,7 +5275,7 @@ var app = (function () {
|
||||
return child_ctx;
|
||||
}
|
||||
|
||||
// (20:1) <Button new_layout={back} my_class="back icon" my_title="go back {back}">
|
||||
// (19:1) <Button new_layout={back} my_class="back icon" my_title="go back {back}">
|
||||
function create_default_slot_4$3(ctx) {
|
||||
let t;
|
||||
|
||||
@@ -5289,14 +5295,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot_4$3.name,
|
||||
type: "slot",
|
||||
source: "(20:1) <Button new_layout={back} my_class=\\\"back icon\\\" my_title=\\\"go back {back}\\\">",
|
||||
source: "(19:1) <Button new_layout={back} my_class=\\\"back icon\\\" my_title=\\\"go back {back}\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (25:1) <Button my_class="new deactivate">
|
||||
// (24:1) <Button my_class="new deactivate">
|
||||
function create_default_slot_3$4(ctx) {
|
||||
let t;
|
||||
|
||||
@@ -5316,14 +5322,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot_3$4.name,
|
||||
type: "slot",
|
||||
source: "(25:1) <Button my_class=\\\"new deactivate\\\">",
|
||||
source: "(24:1) <Button my_class=\\\"new deactivate\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (30:1) <Button new_layout="close" my_class="close icon">
|
||||
// (29:1) <Button new_layout="close" my_class="close icon">
|
||||
function create_default_slot_2$8(ctx) {
|
||||
let t;
|
||||
|
||||
@@ -5343,14 +5349,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot_2$8.name,
|
||||
type: "slot",
|
||||
source: "(30:1) <Button new_layout=\\\"close\\\" my_class=\\\"close icon\\\">",
|
||||
source: "(29:1) <Button new_layout=\\\"close\\\" my_class=\\\"close icon\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (36:2) <Button new_layout="create" my_class="create">
|
||||
// (35:2) <Button new_layout="create" my_class="create">
|
||||
function create_default_slot_1$8(ctx) {
|
||||
let t;
|
||||
|
||||
@@ -5370,7 +5376,7 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot_1$8.name,
|
||||
type: "slot",
|
||||
source: "(36:2) <Button new_layout=\\\"create\\\" my_class=\\\"create\\\">",
|
||||
source: "(35:2) <Button new_layout=\\\"create\\\" my_class=\\\"create\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
@@ -5399,7 +5405,7 @@ var app = (function () {
|
||||
return block;
|
||||
}
|
||||
|
||||
// (46:3) {:then rooms}
|
||||
// (45:3) {:then rooms}
|
||||
function create_then_block$2(ctx) {
|
||||
let each_1_anchor;
|
||||
let current;
|
||||
@@ -5488,14 +5494,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_then_block$2.name,
|
||||
type: "then",
|
||||
source: "(46:3) {:then rooms}",
|
||||
source: "(45:3) {:then rooms}",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (48:5) <Button my_class="list" on_click={function() {join_rooms(room)}}>
|
||||
// (47:5) <Button my_class="list" on_click={function() {join_rooms(room)}}>
|
||||
function create_default_slot$9(ctx) {
|
||||
let t0_value = /*room*/ ctx[4].name + "";
|
||||
let t0;
|
||||
@@ -5521,14 +5527,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot$9.name,
|
||||
type: "slot",
|
||||
source: "(48:5) <Button my_class=\\\"list\\\" on_click={function() {join_rooms(room)}}>",
|
||||
source: "(47:5) <Button my_class=\\\"list\\\" on_click={function() {join_rooms(room)}}>",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (47:4) {#each rooms as room}
|
||||
// (46:4) {#each rooms as room}
|
||||
function create_each_block$6(ctx) {
|
||||
let button;
|
||||
let current;
|
||||
@@ -5583,14 +5589,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_each_block$6.name,
|
||||
type: "each",
|
||||
source: "(47:4) {#each rooms as room}",
|
||||
source: "(46:4) {#each rooms as room}",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (44:17) <p>rooms are loading...</p> {:then rooms}
|
||||
// (43:17) <p>rooms are loading...</p> {:then rooms}
|
||||
function create_pending_block$2(ctx) {
|
||||
let p;
|
||||
|
||||
@@ -5598,7 +5604,7 @@ var app = (function () {
|
||||
c: function create() {
|
||||
p = element("p");
|
||||
p.textContent = "rooms are loading...";
|
||||
add_location(p, file$n, 44, 4, 1114);
|
||||
add_location(p, file$n, 43, 4, 1082);
|
||||
},
|
||||
m: function mount(target, anchor) {
|
||||
insert_dev(target, p, anchor);
|
||||
@@ -5615,7 +5621,7 @@ var app = (function () {
|
||||
block,
|
||||
id: create_pending_block$2.name,
|
||||
type: "pending",
|
||||
source: "(44:17) <p>rooms are loading...</p> {:then rooms}",
|
||||
source: "(43:17) <p>rooms are loading...</p> {:then rooms}",
|
||||
ctx
|
||||
});
|
||||
|
||||
@@ -5716,17 +5722,17 @@ var app = (function () {
|
||||
p1.textContent = "/ there are no public rooms yet /";
|
||||
t7 = space();
|
||||
info.block.c();
|
||||
add_location(p0, file$n, 38, 2, 934);
|
||||
add_location(p0, file$n, 37, 2, 902);
|
||||
attr_dev(p1, "class", "__center");
|
||||
add_location(p1, file$n, 41, 4, 1024);
|
||||
add_location(p1, file$n, 40, 4, 992);
|
||||
attr_dev(div0, "class", "__show_if_only_child");
|
||||
add_location(div0, file$n, 40, 3, 985);
|
||||
add_location(div0, file$n, 39, 3, 953);
|
||||
attr_dev(div1, "class", "public_rooms");
|
||||
add_location(div1, file$n, 39, 2, 955);
|
||||
add_location(div1, file$n, 38, 2, 923);
|
||||
attr_dev(div2, "class", "panel panel_new __border_top");
|
||||
add_location(div2, file$n, 34, 1, 818);
|
||||
add_location(div2, file$n, 33, 1, 786);
|
||||
attr_dev(div3, "class", "grid_box svelte-1b4c0qx");
|
||||
add_location(div3, file$n, 16, 0, 509);
|
||||
add_location(div3, file$n, 15, 0, 477);
|
||||
},
|
||||
l: function claim(nodes) {
|
||||
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
|
||||
@@ -5842,7 +5848,6 @@ var app = (function () {
|
||||
async function join_rooms(room) {
|
||||
console.log("inside join_room");
|
||||
console.log("room:", room);
|
||||
console.log("room:", room);
|
||||
const updated_room = await join_room(room);
|
||||
console.log("updated room:", updated_room);
|
||||
await change_room(updated_room);
|
||||
@@ -7270,7 +7275,7 @@ var app = (function () {
|
||||
const { console: console_1$9 } = globals;
|
||||
const file$i = "src/pieces/chat/Layout_create.svelte";
|
||||
|
||||
// (38:1) <Button new_layout={back} my_class="back icon" my_title="go back {back}">
|
||||
// (42:1) <Button new_layout={back} my_class="back icon" my_title="go back {back}">
|
||||
function create_default_slot_2$4(ctx) {
|
||||
let t;
|
||||
|
||||
@@ -7290,14 +7295,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot_2$4.name,
|
||||
type: "slot",
|
||||
source: "(38:1) <Button new_layout={back} my_class=\\\"back icon\\\" my_title=\\\"go back {back}\\\">",
|
||||
source: "(42:1) <Button new_layout={back} my_class=\\\"back icon\\\" my_title=\\\"go back {back}\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (43:1) <Button my_class="create deactivate">
|
||||
// (47:1) <Button my_class="create deactivate">
|
||||
function create_default_slot_1$4(ctx) {
|
||||
let t;
|
||||
|
||||
@@ -7317,14 +7322,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot_1$4.name,
|
||||
type: "slot",
|
||||
source: "(43:1) <Button my_class=\\\"create deactivate\\\">",
|
||||
source: "(47:1) <Button my_class=\\\"create deactivate\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (48:1) <Button new_layout="close" my_class="close icon">
|
||||
// (52:1) <Button new_layout="close" my_class="close icon">
|
||||
function create_default_slot$5(ctx) {
|
||||
let t;
|
||||
|
||||
@@ -7344,14 +7349,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot$5.name,
|
||||
type: "slot",
|
||||
source: "(48:1) <Button new_layout=\\\"close\\\" my_class=\\\"close icon\\\">",
|
||||
source: "(52:1) <Button new_layout=\\\"close\\\" my_class=\\\"close icon\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (55:3) {#if response.status >= 300}
|
||||
// (59:3) {#if response.status >= 300}
|
||||
function create_if_block_1$5(ctx) {
|
||||
let warning;
|
||||
let current;
|
||||
@@ -7392,14 +7397,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_if_block_1$5.name,
|
||||
type: "if",
|
||||
source: "(55:3) {#if response.status >= 300}",
|
||||
source: "(59:3) {#if response.status >= 300}",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (80:3) {#if room_type === 'protected'}
|
||||
// (84:3) {#if room_type === 'protected'}
|
||||
function create_if_block$b(ctx) {
|
||||
let div;
|
||||
let label;
|
||||
@@ -7418,10 +7423,10 @@ var app = (function () {
|
||||
t1 = space();
|
||||
input = element("input");
|
||||
attr_dev(p, "class", "svelte-1ulnmwp");
|
||||
add_location(p, file$i, 81, 28, 2570);
|
||||
add_location(p, file$i, 85, 28, 2632);
|
||||
attr_dev(label, "for", "chat_pswd");
|
||||
attr_dev(label, "class", "svelte-1ulnmwp");
|
||||
add_location(label, file$i, 81, 5, 2547);
|
||||
add_location(label, file$i, 85, 5, 2609);
|
||||
attr_dev(input, "id", "chat_pswd");
|
||||
attr_dev(input, "type", "password");
|
||||
attr_dev(input, "placeholder", "minimum 8 characters");
|
||||
@@ -7429,9 +7434,9 @@ var app = (function () {
|
||||
attr_dev(input, "name", "password");
|
||||
input.required = true;
|
||||
attr_dev(input, "class", "svelte-1ulnmwp");
|
||||
add_location(input, file$i, 82, 5, 2610);
|
||||
add_location(input, file$i, 86, 5, 2672);
|
||||
attr_dev(div, "class", "svelte-1ulnmwp");
|
||||
add_location(div, file$i, 80, 4, 2536);
|
||||
add_location(div, file$i, 84, 4, 2598);
|
||||
},
|
||||
m: function mount(target, anchor) {
|
||||
insert_dev(target, div, anchor);
|
||||
@@ -7462,7 +7467,7 @@ var app = (function () {
|
||||
block,
|
||||
id: create_if_block$b.name,
|
||||
type: "if",
|
||||
source: "(80:3) {#if room_type === 'protected'}",
|
||||
source: "(84:3) {#if room_type === 'protected'}",
|
||||
ctx
|
||||
});
|
||||
|
||||
@@ -7581,18 +7586,18 @@ var app = (function () {
|
||||
t16 = space();
|
||||
input4 = element("input");
|
||||
attr_dev(p0, "class", "svelte-1ulnmwp");
|
||||
add_location(p0, file$i, 58, 26, 1500);
|
||||
add_location(p0, file$i, 62, 26, 1562);
|
||||
attr_dev(label0, "for", "chat_name");
|
||||
attr_dev(label0, "class", "svelte-1ulnmwp");
|
||||
add_location(label0, file$i, 58, 3, 1477);
|
||||
add_location(label0, file$i, 62, 3, 1539);
|
||||
attr_dev(input0, "id", "chat_name");
|
||||
attr_dev(input0, "name", "room_name");
|
||||
attr_dev(input0, "placeholder", input0_placeholder_value = "allowed special characters: " + /*allowed_chars*/ ctx[1]);
|
||||
input0.required = true;
|
||||
attr_dev(input0, "class", "svelte-1ulnmwp");
|
||||
add_location(input0, file$i, 62, 3, 1699);
|
||||
add_location(input0, file$i, 66, 3, 1761);
|
||||
attr_dev(p1, "class", "svelte-1ulnmwp");
|
||||
add_location(p1, file$i, 65, 4, 1900);
|
||||
add_location(p1, file$i, 69, 4, 1962);
|
||||
attr_dev(input1, "id", "chat_public");
|
||||
attr_dev(input1, "type", "radio");
|
||||
attr_dev(input1, "name", "room_type");
|
||||
@@ -7601,12 +7606,12 @@ var app = (function () {
|
||||
input1.required = true;
|
||||
attr_dev(input1, "class", "svelte-1ulnmwp");
|
||||
/*$$binding_groups*/ ctx[9][0].push(input1);
|
||||
add_location(input1, file$i, 66, 4, 1918);
|
||||
add_location(input1, file$i, 70, 4, 1980);
|
||||
attr_dev(label1, "for", "chat_public");
|
||||
attr_dev(label1, "class", "_radio svelte-1ulnmwp");
|
||||
add_location(label1, file$i, 64, 3, 1855);
|
||||
add_location(label1, file$i, 68, 3, 1917);
|
||||
attr_dev(p2, "class", "svelte-1ulnmwp");
|
||||
add_location(p2, file$i, 70, 4, 2111);
|
||||
add_location(p2, file$i, 74, 4, 2173);
|
||||
attr_dev(input2, "id", "chat_private");
|
||||
attr_dev(input2, "type", "radio");
|
||||
attr_dev(input2, "name", "room_type");
|
||||
@@ -7615,12 +7620,12 @@ var app = (function () {
|
||||
input2.required = true;
|
||||
attr_dev(input2, "class", "svelte-1ulnmwp");
|
||||
/*$$binding_groups*/ ctx[9][0].push(input2);
|
||||
add_location(input2, file$i, 71, 4, 2130);
|
||||
add_location(input2, file$i, 75, 4, 2192);
|
||||
attr_dev(label2, "for", "chat_private");
|
||||
attr_dev(label2, "class", "_radio hide svelte-1ulnmwp");
|
||||
add_location(label2, file$i, 69, 3, 2060);
|
||||
add_location(label2, file$i, 73, 3, 2122);
|
||||
attr_dev(p3, "class", "svelte-1ulnmwp");
|
||||
add_location(p3, file$i, 75, 4, 2329);
|
||||
add_location(p3, file$i, 79, 4, 2391);
|
||||
attr_dev(input3, "id", "chat_protected");
|
||||
attr_dev(input3, "type", "radio");
|
||||
attr_dev(input3, "name", "room_type");
|
||||
@@ -7629,20 +7634,20 @@ var app = (function () {
|
||||
input3.required = true;
|
||||
attr_dev(input3, "class", "svelte-1ulnmwp");
|
||||
/*$$binding_groups*/ ctx[9][0].push(input3);
|
||||
add_location(input3, file$i, 76, 4, 2350);
|
||||
add_location(input3, file$i, 80, 4, 2412);
|
||||
attr_dev(label3, "for", "chat_protected");
|
||||
attr_dev(label3, "class", "_radio hide svelte-1ulnmwp");
|
||||
add_location(label3, file$i, 74, 3, 2276);
|
||||
add_location(label3, file$i, 78, 3, 2338);
|
||||
attr_dev(input4, "type", "submit");
|
||||
input4.value = "⮡";
|
||||
attr_dev(input4, "class", "svelte-1ulnmwp");
|
||||
add_location(input4, file$i, 85, 3, 2774);
|
||||
add_location(input4, file$i, 89, 3, 2836);
|
||||
attr_dev(form, "class", "svelte-1ulnmwp");
|
||||
add_location(form, file$i, 53, 2, 1326);
|
||||
add_location(form, file$i, 57, 2, 1388);
|
||||
attr_dev(div0, "class", "panel panel_create __border_top svelte-1ulnmwp");
|
||||
add_location(div0, file$i, 52, 1, 1278);
|
||||
add_location(div0, file$i, 56, 1, 1340);
|
||||
attr_dev(div1, "class", "grid_box svelte-1ulnmwp");
|
||||
add_location(div1, file$i, 34, 0, 957);
|
||||
add_location(div1, file$i, 38, 0, 1019);
|
||||
},
|
||||
l: function claim(nodes) {
|
||||
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
|
||||
@@ -7844,12 +7849,13 @@ var app = (function () {
|
||||
async function handleSubmit(evt) {
|
||||
let formIsValid = evt.target.checkValidity();
|
||||
if (!formIsValid) return;
|
||||
let room = { name: room_name, type: room_type };
|
||||
|
||||
// send the new room
|
||||
$$invalidate(5, response = await create_room(room_name, room_type));
|
||||
$$invalidate(5, response = await create_room(room));
|
||||
|
||||
// go to room
|
||||
if (response.status === 200) await change_room(room_name);
|
||||
if (response.status === 200) await change_room(response.room);
|
||||
}
|
||||
|
||||
const writable_props = ['back'];
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,6 @@
|
||||
export interface Room
|
||||
{
|
||||
name: string;
|
||||
type: "public" | "protected" | "private" | "direct" | "user";
|
||||
users?: string[];
|
||||
}
|
||||
@@ -33,12 +33,16 @@
|
||||
if (!formIsValid)
|
||||
return;
|
||||
|
||||
let room = {
|
||||
name: room_name,
|
||||
type: room_type,
|
||||
};
|
||||
// send the new room
|
||||
response = await create_room(room_name, room_type);
|
||||
response = await create_room(room);
|
||||
|
||||
// go to room
|
||||
if (response.status === 200)
|
||||
await change_room(room_name);
|
||||
await change_room(response.room);
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
@@ -8,10 +8,12 @@
|
||||
let rooms = get_my_rooms();
|
||||
|
||||
// go to clicked room
|
||||
async function go_to_room(evt)
|
||||
async function go_to_room(room)
|
||||
{
|
||||
console.log("inside go_to_room");
|
||||
await change_room(evt.target.innerText);
|
||||
|
||||
console.log("room:", room);
|
||||
await change_room(room);
|
||||
await get_room_messages();
|
||||
}
|
||||
|
||||
@@ -45,7 +47,7 @@
|
||||
<p>rooms are loading...</p>
|
||||
{:then rooms}
|
||||
{#each rooms as room}
|
||||
<Button my_class="list" on_click={go_to_room}>
|
||||
<Button my_class="list" on_click={function() {go_to_room(room)}}>
|
||||
{room.name}
|
||||
</Button>
|
||||
{/each}
|
||||
|
||||
@@ -9,10 +9,9 @@
|
||||
let rooms = get_all_rooms();
|
||||
|
||||
// join the room
|
||||
async function join_rooms(room: object)
|
||||
async function join_rooms(room)
|
||||
{
|
||||
console.log("inside join_room");
|
||||
console.log("room:", room);
|
||||
|
||||
console.log("room:", room);
|
||||
const updated_room = await join_room(room);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { msgs, user, layout, socket, current_room_name } from './Store_chat';
|
||||
import type { Room } from './Interface_chat';
|
||||
|
||||
export async function get_room_messages()
|
||||
{
|
||||
@@ -19,36 +20,30 @@ export async function get_room_messages()
|
||||
msgs.set(messages);
|
||||
}
|
||||
|
||||
export async function create_room(room_name, room_type)
|
||||
export async function create_room(room: Room)
|
||||
{
|
||||
console.log("in create_room");
|
||||
|
||||
let form_data = {
|
||||
room_name: room_name,
|
||||
room_type: room_type,
|
||||
};
|
||||
|
||||
// send the new room
|
||||
const response = await fetch('/api/v2/chat/create', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(form_data),
|
||||
body: JSON.stringify(room),
|
||||
});
|
||||
|
||||
// get response status and message
|
||||
let response_status = response.status;
|
||||
let data = await response.json();
|
||||
let response_message = "";
|
||||
if (data.message)
|
||||
response_message = data.message;
|
||||
|
||||
return {
|
||||
status: response_status,
|
||||
message: response_message
|
||||
message: data.message,
|
||||
room: data.room,
|
||||
};
|
||||
}
|
||||
|
||||
export async function join_room(room)
|
||||
export async function join_room(room: Room)
|
||||
{
|
||||
console.log("in join_room");
|
||||
|
||||
@@ -62,10 +57,11 @@ export async function join_room(room)
|
||||
return data.room;
|
||||
}
|
||||
|
||||
export async function change_room(room)
|
||||
export async function change_room(room: Room)
|
||||
{
|
||||
console.log("in change_room");
|
||||
|
||||
console.log("room:", room);
|
||||
const response = await fetch('/api/v2/chat/change', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
@@ -92,6 +88,7 @@ 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);
|
||||
|
||||
return data.rooms;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user