wip multiple rooms
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
import { WebSocketGateway, SubscribeMessage, WebSocketServer, MessageBody, ConnectedSocket, OnGatewayConnection, OnGatewayDisconnect } from '@nestjs/websockets';
|
||||
import { UseGuards } from '@nestjs/common';
|
||||
import { UsersService } from 'src/users/users.service';
|
||||
import { PaginationQueryDto } from 'src/common/dto/pagination-query.dto';
|
||||
import { ChatService } from './chat.service';
|
||||
import { AuthenticateGuard } from 'src/auth/42/guards/42guards';
|
||||
|
||||
@WebSocketGateway(5000, {
|
||||
path: '/chat',
|
||||
@@ -31,19 +29,22 @@ export class ChatGateway
|
||||
console.log('- Client disconnected :', client.id, client.username);
|
||||
}
|
||||
|
||||
// @UseGuards(AuthenticateGuard)
|
||||
@SubscribeMessage('join')
|
||||
joinRoom(@ConnectedSocket() socket, @MessageBody() room_name: string): void
|
||||
{
|
||||
console.log('- in joinRoom gateway');
|
||||
console.log(room_name);
|
||||
socket.join(room_name);
|
||||
}
|
||||
|
||||
@SubscribeMessage('message')
|
||||
// handleMessage(@MessageBody() message: string): void {
|
||||
// handleMessage(client: any, message: string): void {
|
||||
handleMessage(@ConnectedSocket() client, @MessageBody() message: string): void{
|
||||
// const paginationQuery = new PaginationQueryDto();
|
||||
// const users = this.usersService.findAll(paginationQuery);
|
||||
// console.log('users :', users);
|
||||
// this.server.emit('message', message);
|
||||
console.log('client.username :', client.username);
|
||||
client.local.emit('message', client.username, message);
|
||||
// this.chatService.add_message(this.server, message);
|
||||
this.chatService.addMessageToCurrentRoom(client.username, message);
|
||||
async handleMessage(@ConnectedSocket() socket, @MessageBody() message: string): Promise<void>
|
||||
{
|
||||
console.log('- in handleMessage gateway');
|
||||
let room_name = await this.chatService.getCurrentRoom(socket.username);
|
||||
console.log('room_name:', room_name);
|
||||
socket.to(room_name).emit('message', socket.username, message);
|
||||
this.chatService.addMessageToCurrentRoom(socket.username, message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,10 @@ export class ChatService {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
|
||||
/* GETTERS ************************************************
|
||||
*/
|
||||
|
||||
async getMyRooms(user: User)
|
||||
{
|
||||
console.log("-- in getMyRooms service");
|
||||
@@ -49,81 +53,79 @@ export class ChatService {
|
||||
async getAllNotMyRooms(user: User)
|
||||
{
|
||||
console.log("-- in getAllNotMyRooms service");
|
||||
const user_db = await this.findUserByName(user.username);
|
||||
const user_db = await this.getUserByName(user.username);
|
||||
const rooms = await this.chatroomRepository
|
||||
.createQueryBuilder('chatroom')
|
||||
.where('chatroom.type != :type', { type: 'private' })
|
||||
.andWhere('chatroom.users NOT LIKE :user_name', { user_name: `%${user.username}%` })
|
||||
.getMany();
|
||||
//const users = await this.findAllUsers();
|
||||
//const users = await this.getAllUsers();
|
||||
//let allRooms = [...rooms, ...users];
|
||||
|
||||
return rooms;
|
||||
}
|
||||
|
||||
async findRoomByName(name: string)
|
||||
async getMessagesFromCurrentRoom(user: User)
|
||||
{
|
||||
console.log("-- in findUserByName service");
|
||||
console.log("-- in getMessagesFromCurrentRoom service");
|
||||
const user_db = await this.usersService.findOneByFourtyTwoId(user.fortyTwoId);
|
||||
const currentRoom = await this.getRoomByName(user_db.currentRoom);
|
||||
|
||||
return currentRoom.messages;
|
||||
}
|
||||
|
||||
async getCurrentRoom(username: string)
|
||||
{
|
||||
console.log("-- in getCurrentRoom service");
|
||||
const user_db = await this.getUserByName(username);
|
||||
|
||||
return user_db.currentRoom;
|
||||
}
|
||||
|
||||
async getRoomByName(name: string)
|
||||
{
|
||||
console.log("-- in getRoomByName service");
|
||||
const room = await this.chatroomRepository
|
||||
.createQueryBuilder('chatroom')
|
||||
.where('chatroom.name = :name', { name: name })
|
||||
.getOne();
|
||||
|
||||
console.log("room:", room, ", typeof room:", typeof room);
|
||||
return room;
|
||||
}
|
||||
|
||||
async findRoomById(id: number)
|
||||
async getRoomById(id: number)
|
||||
{
|
||||
console.log("-- in findRoomById service");
|
||||
console.log("-- in getRoomById service");
|
||||
const room = await this.chatroomRepository
|
||||
.createQueryBuilder('chatroom')
|
||||
.where('chatroom.id = :id', { id: id })
|
||||
.getOne();
|
||||
|
||||
console.log("room:", room, ", typeof room:", typeof room);
|
||||
return room;
|
||||
}
|
||||
|
||||
/* temp *****************************************
|
||||
|
||||
/* SETTERS ************************************************
|
||||
*/
|
||||
async findUserByName(name: string)
|
||||
{
|
||||
console.log("-- in findUserByName service");
|
||||
const user = await this.userRepository
|
||||
.createQueryBuilder('user')
|
||||
.where('user.username = :name', { name: name })
|
||||
.getOne();
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
/* temp *****************************************
|
||||
*/
|
||||
async findAllUsers()
|
||||
{
|
||||
console.log("-- in findAllUsers service");
|
||||
const users = await this.userRepository
|
||||
.createQueryBuilder('user')
|
||||
.getMany();
|
||||
|
||||
return users;
|
||||
}
|
||||
|
||||
async setCurrentRoom(user: User, name: string)
|
||||
{
|
||||
console.log("-- in setCurrentRoom service");
|
||||
const user_db = await this.findUserByName(user.username);
|
||||
const user_db = await this.getUserByName(user.username);
|
||||
user_db.currentRoom = name;
|
||||
this.userRepository.save(user_db);
|
||||
|
||||
return `room "${name}" is now current room`;
|
||||
}
|
||||
|
||||
|
||||
/* ADDERS *************************************************
|
||||
*/
|
||||
|
||||
async addUserToNewRoom(user: User, createRoomDto: createRoomDto)
|
||||
{
|
||||
console.log("-- in addUserToRoom service");
|
||||
const room = await this.findRoomByName(createRoomDto.room_name);
|
||||
const room = await this.getRoomByName(createRoomDto.room_name);
|
||||
if (room)
|
||||
throw new HttpException(`This room already exist`, HttpStatus.CONFLICT);
|
||||
|
||||
@@ -144,7 +146,7 @@ export class ChatService {
|
||||
async addUserToRoom(user: User, joinRoomDto: joinRoomDto)
|
||||
{
|
||||
console.log("-- in addUserToRoom service");
|
||||
const room = await this.findRoomByName(joinRoomDto.room_name);
|
||||
const room = await this.getRoomByName(joinRoomDto.room_name);
|
||||
if (room.users.includes(user.username))
|
||||
throw new HttpException(`your have already join this room`, HttpStatus.CONFLICT);
|
||||
|
||||
@@ -153,15 +155,30 @@ export class ChatService {
|
||||
this.chatroomRepository.save(room);
|
||||
|
||||
const rooms = await this.getMyRooms(user);
|
||||
console.log("rooms:", rooms);
|
||||
const allRooms = await this.getAllRooms();
|
||||
console.log("allRooms:", allRooms);
|
||||
|
||||
this.setCurrentRoom(user, joinRoomDto.room_name)
|
||||
|
||||
return "successfull joining room";
|
||||
}
|
||||
|
||||
async addMessageToCurrentRoom(name: string, message: string)
|
||||
{
|
||||
console.log("-- in addMessageToCurrentRoom service");
|
||||
const user_db = await this.getUserByName(name);
|
||||
const currentRoom = await this.getRoomByName(user_db.currentRoom);
|
||||
let chat_message = {
|
||||
name: name,
|
||||
message: message,
|
||||
};
|
||||
currentRoom.messages.push(chat_message);
|
||||
this.chatroomRepository.save(currentRoom);
|
||||
}
|
||||
|
||||
|
||||
/* REMOVERS ***********************************************
|
||||
*/
|
||||
|
||||
async removeUserFromRoom(user: User, room_name: string)
|
||||
{
|
||||
console.log("-- in removeUserFromRoom service");
|
||||
@@ -169,27 +186,34 @@ export class ChatService {
|
||||
// remove user
|
||||
}
|
||||
|
||||
async addMessageToCurrentRoom(name: string, message: string)
|
||||
|
||||
/* SEARCH IN USER *****************************************
|
||||
*/
|
||||
|
||||
async getUserByName(name: string)
|
||||
{
|
||||
console.log("-- in addMessageToCurrentRoom service");
|
||||
const user_db = await this.findUserByName(name);
|
||||
const currentRoom = await this.findRoomByName(user_db.currentRoom);
|
||||
let chat_message = {
|
||||
name: name,
|
||||
message: message,
|
||||
};
|
||||
console.log(message);
|
||||
currentRoom.messages.push(chat_message);
|
||||
this.chatroomRepository.save(currentRoom);
|
||||
console.log("-- in getUserByName service");
|
||||
const user = await this.userRepository
|
||||
.createQueryBuilder('user')
|
||||
.where('user.username = :name', { name: name })
|
||||
.getOne();
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
async getMessagesFromCurrentRoom(user: User)
|
||||
async getAllUsers()
|
||||
{
|
||||
console.log("-- in getMessagesFromCurrentRoom service");
|
||||
const user_db = await this.usersService.findOneByFourtyTwoId(user.fortyTwoId);
|
||||
const currentRoom = await this.findRoomByName(user_db.currentRoom);
|
||||
console.log("-- in getAllUsers service");
|
||||
const users = await this.userRepository
|
||||
.createQueryBuilder('user')
|
||||
.getMany();
|
||||
|
||||
return currentRoom.messages;
|
||||
return users;
|
||||
}
|
||||
|
||||
|
||||
/* SOCKET EVENTS ******************************************
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -56,13 +56,6 @@ export class User {
|
||||
|
||||
// ROOMS :
|
||||
|
||||
//@OneToMany(type => Chatroom, chatroom => chatroom.owner)
|
||||
//ownedRooms: Chatroom[];
|
||||
|
||||
//@ManyToMany(type => Chatroom)
|
||||
//@JoinTable()
|
||||
//userRooms: Chatroom[];
|
||||
|
||||
@Column({ nullable: true })
|
||||
currentRoom: string;
|
||||
currentRoom: string; // room name
|
||||
}
|
||||
|
||||
@@ -3912,7 +3912,7 @@ var app = (function () {
|
||||
return child_ctx;
|
||||
}
|
||||
|
||||
// (50:1) <Button bind:layout new_layout="settings" my_class="settings dots icon">
|
||||
// (53:1) <Button bind:layout new_layout="settings" my_class="settings dots icon">
|
||||
function create_default_slot_3$5(ctx) {
|
||||
let t;
|
||||
|
||||
@@ -3932,14 +3932,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot_3$5.name,
|
||||
type: "slot",
|
||||
source: "(50:1) <Button bind:layout new_layout=\\\"settings\\\" my_class=\\\"settings dots icon\\\">",
|
||||
source: "(53:1) <Button bind:layout new_layout=\\\"settings\\\" my_class=\\\"settings dots icon\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (55:1) <Button bind:layout new_layout="new" my_class="new transparent">
|
||||
// (58:1) <Button bind:layout new_layout="new" my_class="new transparent">
|
||||
function create_default_slot_2$9(ctx) {
|
||||
let t;
|
||||
|
||||
@@ -3959,14 +3959,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot_2$9.name,
|
||||
type: "slot",
|
||||
source: "(55:1) <Button bind:layout new_layout=\\\"new\\\" my_class=\\\"new transparent\\\">",
|
||||
source: "(58:1) <Button bind:layout new_layout=\\\"new\\\" my_class=\\\"new transparent\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (60:1) <Button bind:layout new_layout="close" my_class="close icon">
|
||||
// (63:1) <Button bind:layout new_layout="close" my_class="close icon">
|
||||
function create_default_slot_1$9(ctx) {
|
||||
let t;
|
||||
|
||||
@@ -3986,7 +3986,7 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot_1$9.name,
|
||||
type: "slot",
|
||||
source: "(60:1) <Button bind:layout new_layout=\\\"close\\\" my_class=\\\"close icon\\\">",
|
||||
source: "(63:1) <Button bind:layout new_layout=\\\"close\\\" my_class=\\\"close icon\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
@@ -4015,7 +4015,7 @@ var app = (function () {
|
||||
return block;
|
||||
}
|
||||
|
||||
// (74:3) {:then}
|
||||
// (77:3) {:then}
|
||||
function create_then_block$2(ctx) {
|
||||
let each_1_anchor;
|
||||
let current;
|
||||
@@ -4104,14 +4104,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_then_block$2.name,
|
||||
type: "then",
|
||||
source: "(74:3) {:then}",
|
||||
source: "(77:3) {:then}",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (76:5) <Button my_class="list" on_click={get_room_messages}>
|
||||
// (79:5) <Button my_class="list" on_click={get_room_messages}>
|
||||
function create_default_slot$b(ctx) {
|
||||
let t0_value = /*room*/ ctx[7].name + "";
|
||||
let t0;
|
||||
@@ -4139,14 +4139,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot$b.name,
|
||||
type: "slot",
|
||||
source: "(76:5) <Button my_class=\\\"list\\\" on_click={get_room_messages}>",
|
||||
source: "(79:5) <Button my_class=\\\"list\\\" on_click={get_room_messages}>",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (75:4) {#each rooms as room}
|
||||
// (78:4) {#each rooms as room}
|
||||
function create_each_block$6(ctx) {
|
||||
let button;
|
||||
let current;
|
||||
@@ -4196,14 +4196,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_each_block$6.name,
|
||||
type: "each",
|
||||
source: "(75:4) {#each rooms as room}",
|
||||
source: "(78:4) {#each rooms as room}",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (71:21) <!-- promise is pending --> <p>rooms are loaded...</p> {:then}
|
||||
// (74:21) <!-- promise is pending --> <p>rooms are loaded...</p> {:then}
|
||||
function create_pending_block$2(ctx) {
|
||||
let p;
|
||||
|
||||
@@ -4211,7 +4211,7 @@ var app = (function () {
|
||||
c: function create() {
|
||||
p = element("p");
|
||||
p.textContent = "rooms are loaded...";
|
||||
add_location(p, file$p, 72, 4, 1632);
|
||||
add_location(p, file$p, 75, 4, 1671);
|
||||
},
|
||||
m: function mount(target, anchor) {
|
||||
insert_dev(target, p, anchor);
|
||||
@@ -4228,7 +4228,7 @@ var app = (function () {
|
||||
block,
|
||||
id: create_pending_block$2.name,
|
||||
type: "pending",
|
||||
source: "(71:21) <!-- promise is pending --> <p>rooms are loaded...</p> {:then}",
|
||||
source: "(74:21) <!-- promise is pending --> <p>rooms are loaded...</p> {:then}",
|
||||
ctx
|
||||
});
|
||||
|
||||
@@ -4342,17 +4342,17 @@ var app = (function () {
|
||||
t6 = space();
|
||||
info.block.c();
|
||||
attr_dev(p0, "class", "title svelte-1jygwt2");
|
||||
add_location(p0, file$p, 65, 2, 1400);
|
||||
add_location(p0, file$p, 68, 2, 1439);
|
||||
attr_dev(p1, "class", "__center");
|
||||
add_location(p1, file$p, 68, 4, 1510);
|
||||
add_location(p1, file$p, 71, 4, 1549);
|
||||
attr_dev(div0, "class", "__show_if_only_child");
|
||||
add_location(div0, file$p, 67, 3, 1471);
|
||||
add_location(div0, file$p, 70, 3, 1510);
|
||||
attr_dev(div1, "class", "room_list");
|
||||
add_location(div1, file$p, 66, 2, 1444);
|
||||
add_location(div1, file$p, 69, 2, 1483);
|
||||
attr_dev(div2, "class", "panel panel_home __border_top svelte-1jygwt2");
|
||||
add_location(div2, file$p, 64, 1, 1354);
|
||||
add_location(div2, file$p, 67, 1, 1393);
|
||||
attr_dev(div3, "class", "grid_box svelte-1jygwt2");
|
||||
add_location(div3, file$p, 46, 0, 995);
|
||||
add_location(div3, file$p, 49, 0, 1034);
|
||||
},
|
||||
l: function claim(nodes) {
|
||||
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
|
||||
@@ -4481,6 +4481,7 @@ var app = (function () {
|
||||
$$invalidate(1, rooms = data.rooms);
|
||||
});
|
||||
|
||||
// get room messages
|
||||
function get_room_messages() {
|
||||
console.log("in get_room_messages");
|
||||
|
||||
@@ -4497,6 +4498,7 @@ var app = (function () {
|
||||
msgs.update(msgs => data.messages);
|
||||
});
|
||||
|
||||
// go to room
|
||||
$$invalidate(0, layout = "room");
|
||||
}
|
||||
|
||||
@@ -5405,7 +5407,7 @@ var app = (function () {
|
||||
return child_ctx;
|
||||
}
|
||||
|
||||
// (62:1) <Button bind:layout new_layout={back} my_class="back icon" my_title="go back {back}">
|
||||
// (68:1) <Button bind:layout new_layout={back} my_class="back icon" my_title="go back {back}">
|
||||
function create_default_slot_4$2(ctx) {
|
||||
let t;
|
||||
|
||||
@@ -5425,14 +5427,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot_4$2.name,
|
||||
type: "slot",
|
||||
source: "(62:1) <Button bind:layout new_layout={back} my_class=\\\"back icon\\\" my_title=\\\"go back {back}\\\">",
|
||||
source: "(68:1) <Button bind:layout new_layout={back} my_class=\\\"back icon\\\" my_title=\\\"go back {back}\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (67:1) <Button my_class="new deactivate">
|
||||
// (73:1) <Button my_class="new deactivate">
|
||||
function create_default_slot_3$3(ctx) {
|
||||
let t;
|
||||
|
||||
@@ -5452,14 +5454,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot_3$3.name,
|
||||
type: "slot",
|
||||
source: "(67:1) <Button my_class=\\\"new deactivate\\\">",
|
||||
source: "(73:1) <Button my_class=\\\"new deactivate\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (72:1) <Button bind:layout new_layout="close" my_class="close icon">
|
||||
// (78:1) <Button bind:layout new_layout="close" my_class="close icon">
|
||||
function create_default_slot_2$7(ctx) {
|
||||
let t;
|
||||
|
||||
@@ -5479,14 +5481,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot_2$7.name,
|
||||
type: "slot",
|
||||
source: "(72:1) <Button bind:layout new_layout=\\\"close\\\" my_class=\\\"close icon\\\">",
|
||||
source: "(78:1) <Button bind:layout new_layout=\\\"close\\\" my_class=\\\"close icon\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (78:2) <Button bind:layout new_layout="create" my_class="create">
|
||||
// (84:2) <Button bind:layout new_layout="create" my_class="create">
|
||||
function create_default_slot_1$7(ctx) {
|
||||
let t;
|
||||
|
||||
@@ -5506,14 +5508,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot_1$7.name,
|
||||
type: "slot",
|
||||
source: "(78:2) <Button bind:layout new_layout=\\\"create\\\" my_class=\\\"create\\\">",
|
||||
source: "(84:2) <Button bind:layout new_layout=\\\"create\\\" my_class=\\\"create\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (1:0) <script> import Button from './Element_button.svelte'; import { msgs, user }
|
||||
// (1:0) <script> import Button from './Element_button.svelte'; import { msgs, user, socket }
|
||||
function create_catch_block$1(ctx) {
|
||||
const block = {
|
||||
c: noop,
|
||||
@@ -5528,14 +5530,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_catch_block$1.name,
|
||||
type: "catch",
|
||||
source: "(1:0) <script> import Button from './Element_button.svelte'; import { msgs, user }",
|
||||
source: "(1:0) <script> import Button from './Element_button.svelte'; import { msgs, user, socket }",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (89:3) {:then}
|
||||
// (95:3) {:then}
|
||||
function create_then_block$1(ctx) {
|
||||
let each_1_anchor;
|
||||
let current;
|
||||
@@ -5624,14 +5626,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_then_block$1.name,
|
||||
type: "then",
|
||||
source: "(89:3) {:then}",
|
||||
source: "(95:3) {:then}",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (91:5) <Button my_class="list" on_click={join_rooms}>
|
||||
// (97:5) <Button my_class="list" on_click={join_rooms}>
|
||||
function create_default_slot$9(ctx) {
|
||||
let t0_value = /*room*/ ctx[8].name + "";
|
||||
let t0;
|
||||
@@ -5659,14 +5661,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot$9.name,
|
||||
type: "slot",
|
||||
source: "(91:5) <Button my_class=\\\"list\\\" on_click={join_rooms}>",
|
||||
source: "(97:5) <Button my_class=\\\"list\\\" on_click={join_rooms}>",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (90:4) {#each rooms as room}
|
||||
// (96:4) {#each rooms as room}
|
||||
function create_each_block$4(ctx) {
|
||||
let button;
|
||||
let current;
|
||||
@@ -5716,14 +5718,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_each_block$4.name,
|
||||
type: "each",
|
||||
source: "(90:4) {#each rooms as room}",
|
||||
source: "(96:4) {#each rooms as room}",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (86:21) <!-- promise is pending --> <p>rooms are loaded...</p> {:then}
|
||||
// (92:21) <!-- promise is pending --> <p>rooms are loaded...</p> {:then}
|
||||
function create_pending_block$1(ctx) {
|
||||
let p;
|
||||
|
||||
@@ -5731,7 +5733,7 @@ var app = (function () {
|
||||
c: function create() {
|
||||
p = element("p");
|
||||
p.textContent = "rooms are loaded...";
|
||||
add_location(p, file$m, 87, 4, 1783);
|
||||
add_location(p, file$m, 93, 4, 1920);
|
||||
},
|
||||
m: function mount(target, anchor) {
|
||||
insert_dev(target, p, anchor);
|
||||
@@ -5748,7 +5750,7 @@ var app = (function () {
|
||||
block,
|
||||
id: create_pending_block$1.name,
|
||||
type: "pending",
|
||||
source: "(86:21) <!-- promise is pending --> <p>rooms are loaded...</p> {:then}",
|
||||
source: "(92:21) <!-- promise is pending --> <p>rooms are loaded...</p> {:then}",
|
||||
ctx
|
||||
});
|
||||
|
||||
@@ -5875,17 +5877,17 @@ var app = (function () {
|
||||
p1.textContent = "/ there are no public rooms yet /";
|
||||
t7 = space();
|
||||
info.block.c();
|
||||
add_location(p0, file$m, 80, 2, 1567);
|
||||
add_location(p0, file$m, 86, 2, 1704);
|
||||
attr_dev(p1, "class", "__center");
|
||||
add_location(p1, file$m, 83, 4, 1657);
|
||||
add_location(p1, file$m, 89, 4, 1794);
|
||||
attr_dev(div0, "class", "__show_if_only_child");
|
||||
add_location(div0, file$m, 82, 3, 1618);
|
||||
add_location(div0, file$m, 88, 3, 1755);
|
||||
attr_dev(div1, "class", "public_rooms");
|
||||
add_location(div1, file$m, 81, 2, 1588);
|
||||
add_location(div1, file$m, 87, 2, 1725);
|
||||
attr_dev(div2, "class", "panel panel_new __border_top");
|
||||
add_location(div2, file$m, 76, 1, 1439);
|
||||
add_location(div2, file$m, 82, 1, 1576);
|
||||
attr_dev(div3, "class", "grid_box svelte-1b4c0qx");
|
||||
add_location(div3, file$m, 58, 0, 1106);
|
||||
add_location(div3, file$m, 64, 0, 1243);
|
||||
},
|
||||
l: function claim(nodes) {
|
||||
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
|
||||
@@ -6023,10 +6025,12 @@ var app = (function () {
|
||||
$$invalidate(2, rooms = data.rooms);
|
||||
});
|
||||
|
||||
// join the room
|
||||
function join_rooms(evt) {
|
||||
console.log("inside join_rooms");
|
||||
let room_name = { room_name: evt.target.innerText };
|
||||
|
||||
// join room
|
||||
fetch('/api/v2/chat/join', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
@@ -6035,6 +6039,10 @@ var app = (function () {
|
||||
console.log(data);
|
||||
});
|
||||
|
||||
// join socket room
|
||||
socket$1.emit('join', room_name);
|
||||
|
||||
// get messages from room
|
||||
fetch('/api/v2/chat/messages').then(resp => resp.json()).then(data => {
|
||||
console.log(data.messages);
|
||||
|
||||
@@ -6047,9 +6055,9 @@ var app = (function () {
|
||||
msgs.update(msgs => data.messages);
|
||||
});
|
||||
|
||||
// go to room
|
||||
$$invalidate(0, layout = "room");
|
||||
} /*
|
||||
*/
|
||||
}
|
||||
|
||||
const writable_props = ['layout', 'back'];
|
||||
|
||||
@@ -6081,6 +6089,7 @@ var app = (function () {
|
||||
Button: Element_button,
|
||||
msgs,
|
||||
user,
|
||||
socket: socket$1,
|
||||
layout,
|
||||
back,
|
||||
rooms,
|
||||
@@ -7668,7 +7677,7 @@ var app = (function () {
|
||||
const { console: console_1$8 } = globals;
|
||||
const file$h = "src/pieces/chat/Layout_create.svelte";
|
||||
|
||||
// (41:1) <Button bind:layout new_layout={back} my_class="back icon" my_title="go back {back}">
|
||||
// (44:1) <Button bind:layout new_layout={back} my_class="back icon" my_title="go back {back}">
|
||||
function create_default_slot_2$3(ctx) {
|
||||
let t;
|
||||
|
||||
@@ -7688,14 +7697,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot_2$3.name,
|
||||
type: "slot",
|
||||
source: "(41:1) <Button bind:layout new_layout={back} my_class=\\\"back icon\\\" my_title=\\\"go back {back}\\\">",
|
||||
source: "(44:1) <Button bind:layout new_layout={back} my_class=\\\"back icon\\\" my_title=\\\"go back {back}\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (46:1) <Button my_class="create deactivate">
|
||||
// (49:1) <Button my_class="create deactivate">
|
||||
function create_default_slot_1$3(ctx) {
|
||||
let t;
|
||||
|
||||
@@ -7715,14 +7724,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot_1$3.name,
|
||||
type: "slot",
|
||||
source: "(46:1) <Button my_class=\\\"create deactivate\\\">",
|
||||
source: "(49:1) <Button my_class=\\\"create deactivate\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (51:1) <Button bind:layout new_layout="close" my_class="close icon">
|
||||
// (54:1) <Button bind:layout new_layout="close" my_class="close icon">
|
||||
function create_default_slot$5(ctx) {
|
||||
let t;
|
||||
|
||||
@@ -7742,14 +7751,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot$5.name,
|
||||
type: "slot",
|
||||
source: "(51:1) <Button bind:layout new_layout=\\\"close\\\" my_class=\\\"close icon\\\">",
|
||||
source: "(54:1) <Button bind:layout new_layout=\\\"close\\\" my_class=\\\"close icon\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (58:3) {#if response_status >= 300}
|
||||
// (61:3) {#if response_status >= 300}
|
||||
function create_if_block_1$5(ctx) {
|
||||
let warning;
|
||||
let current;
|
||||
@@ -7790,14 +7799,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_if_block_1$5.name,
|
||||
type: "if",
|
||||
source: "(58:3) {#if response_status >= 300}",
|
||||
source: "(61:3) {#if response_status >= 300}",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (80:3) {#if room_type === 'protected'}
|
||||
// (83:3) {#if room_type === 'protected'}
|
||||
function create_if_block$b(ctx) {
|
||||
let div;
|
||||
let label;
|
||||
@@ -7816,10 +7825,10 @@ var app = (function () {
|
||||
t1 = space();
|
||||
input = element("input");
|
||||
attr_dev(p, "class", "svelte-1ulnmwp");
|
||||
add_location(p, file$h, 81, 28, 2596);
|
||||
add_location(p, file$h, 84, 28, 2695);
|
||||
attr_dev(label, "for", "chat_pswd");
|
||||
attr_dev(label, "class", "svelte-1ulnmwp");
|
||||
add_location(label, file$h, 81, 5, 2573);
|
||||
add_location(label, file$h, 84, 5, 2672);
|
||||
attr_dev(input, "id", "chat_pswd");
|
||||
attr_dev(input, "type", "password");
|
||||
attr_dev(input, "placeholder", "minimum 8 characters");
|
||||
@@ -7827,9 +7836,9 @@ var app = (function () {
|
||||
attr_dev(input, "name", "password");
|
||||
input.required = true;
|
||||
attr_dev(input, "class", "svelte-1ulnmwp");
|
||||
add_location(input, file$h, 82, 5, 2636);
|
||||
add_location(input, file$h, 85, 5, 2735);
|
||||
attr_dev(div, "class", "svelte-1ulnmwp");
|
||||
add_location(div, file$h, 80, 4, 2562);
|
||||
add_location(div, file$h, 83, 4, 2661);
|
||||
},
|
||||
m: function mount(target, anchor) {
|
||||
insert_dev(target, div, anchor);
|
||||
@@ -7860,7 +7869,7 @@ var app = (function () {
|
||||
block,
|
||||
id: create_if_block$b.name,
|
||||
type: "if",
|
||||
source: "(80:3) {#if room_type === 'protected'}",
|
||||
source: "(83:3) {#if room_type === 'protected'}",
|
||||
ctx
|
||||
});
|
||||
|
||||
@@ -7995,17 +8004,17 @@ var app = (function () {
|
||||
t16 = space();
|
||||
input4 = element("input");
|
||||
attr_dev(p0, "class", "svelte-1ulnmwp");
|
||||
add_location(p0, file$h, 61, 26, 1749);
|
||||
add_location(p0, file$h, 64, 26, 1848);
|
||||
attr_dev(label0, "for", "chat_name");
|
||||
attr_dev(label0, "class", "svelte-1ulnmwp");
|
||||
add_location(label0, file$h, 61, 3, 1726);
|
||||
add_location(label0, file$h, 64, 3, 1825);
|
||||
attr_dev(input0, "id", "chat_name");
|
||||
attr_dev(input0, "name", "room_name");
|
||||
input0.required = true;
|
||||
attr_dev(input0, "class", "svelte-1ulnmwp");
|
||||
add_location(input0, file$h, 62, 3, 1783);
|
||||
add_location(input0, file$h, 65, 3, 1882);
|
||||
attr_dev(p1, "class", "svelte-1ulnmwp");
|
||||
add_location(p1, file$h, 65, 4, 1926);
|
||||
add_location(p1, file$h, 68, 4, 2025);
|
||||
attr_dev(input1, "id", "chat_public");
|
||||
attr_dev(input1, "type", "radio");
|
||||
attr_dev(input1, "name", "room_type");
|
||||
@@ -8014,12 +8023,12 @@ var app = (function () {
|
||||
input1.required = true;
|
||||
attr_dev(input1, "class", "svelte-1ulnmwp");
|
||||
/*$$binding_groups*/ ctx[12][0].push(input1);
|
||||
add_location(input1, file$h, 66, 4, 1944);
|
||||
add_location(input1, file$h, 69, 4, 2043);
|
||||
attr_dev(label1, "for", "chat_public");
|
||||
attr_dev(label1, "class", "_radio svelte-1ulnmwp");
|
||||
add_location(label1, file$h, 64, 3, 1881);
|
||||
add_location(label1, file$h, 67, 3, 1980);
|
||||
attr_dev(p2, "class", "svelte-1ulnmwp");
|
||||
add_location(p2, file$h, 70, 4, 2137);
|
||||
add_location(p2, file$h, 73, 4, 2236);
|
||||
attr_dev(input2, "id", "chat_private");
|
||||
attr_dev(input2, "type", "radio");
|
||||
attr_dev(input2, "name", "room_type");
|
||||
@@ -8028,12 +8037,12 @@ var app = (function () {
|
||||
input2.required = true;
|
||||
attr_dev(input2, "class", "svelte-1ulnmwp");
|
||||
/*$$binding_groups*/ ctx[12][0].push(input2);
|
||||
add_location(input2, file$h, 71, 4, 2156);
|
||||
add_location(input2, file$h, 74, 4, 2255);
|
||||
attr_dev(label2, "for", "chat_private");
|
||||
attr_dev(label2, "class", "_radio hide svelte-1ulnmwp");
|
||||
add_location(label2, file$h, 69, 3, 2086);
|
||||
add_location(label2, file$h, 72, 3, 2185);
|
||||
attr_dev(p3, "class", "svelte-1ulnmwp");
|
||||
add_location(p3, file$h, 75, 4, 2355);
|
||||
add_location(p3, file$h, 78, 4, 2454);
|
||||
attr_dev(input3, "id", "chat_protected");
|
||||
attr_dev(input3, "type", "radio");
|
||||
attr_dev(input3, "name", "room_type");
|
||||
@@ -8042,20 +8051,20 @@ var app = (function () {
|
||||
input3.required = true;
|
||||
attr_dev(input3, "class", "svelte-1ulnmwp");
|
||||
/*$$binding_groups*/ ctx[12][0].push(input3);
|
||||
add_location(input3, file$h, 76, 4, 2376);
|
||||
add_location(input3, file$h, 79, 4, 2475);
|
||||
attr_dev(label3, "for", "chat_protected");
|
||||
attr_dev(label3, "class", "_radio hide svelte-1ulnmwp");
|
||||
add_location(label3, file$h, 74, 3, 2302);
|
||||
add_location(label3, file$h, 77, 3, 2401);
|
||||
attr_dev(input4, "type", "submit");
|
||||
input4.value = "⮡";
|
||||
attr_dev(input4, "class", "svelte-1ulnmwp");
|
||||
add_location(input4, file$h, 85, 3, 2800);
|
||||
add_location(input4, file$h, 88, 3, 2899);
|
||||
attr_dev(form, "class", "svelte-1ulnmwp");
|
||||
add_location(form, file$h, 56, 2, 1575);
|
||||
add_location(form, file$h, 59, 2, 1674);
|
||||
attr_dev(div0, "class", "panel panel_create __border_top svelte-1ulnmwp");
|
||||
add_location(div0, file$h, 55, 1, 1527);
|
||||
add_location(div0, file$h, 58, 1, 1626);
|
||||
attr_dev(div1, "class", "grid_box svelte-1ulnmwp");
|
||||
add_location(div1, file$h, 37, 0, 1182);
|
||||
add_location(div1, file$h, 40, 0, 1281);
|
||||
},
|
||||
l: function claim(nodes) {
|
||||
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
|
||||
@@ -8275,6 +8284,9 @@ var app = (function () {
|
||||
if (response_data.message) $$invalidate(6, response_message = response_data.message);
|
||||
console.log("response:", response_data, "status:", response_status, "message:", response_message);
|
||||
|
||||
// join socket room
|
||||
socket$1.emit('join', room_name);
|
||||
|
||||
// go to room
|
||||
if (response_status === 200 && response_message === "successfull room creation") $$invalidate(0, layout = "room");
|
||||
}
|
||||
@@ -8328,6 +8340,7 @@ var app = (function () {
|
||||
};
|
||||
|
||||
$$self.$capture_state = () => ({
|
||||
socket: socket$1,
|
||||
Button: Element_button,
|
||||
Warning: Element_warning,
|
||||
layout,
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,5 +1,6 @@
|
||||
<script lang="ts">
|
||||
|
||||
import { socket } from './Store_chat';
|
||||
import Button from './Element_button.svelte';
|
||||
import Warning from './Element_warning.svelte';
|
||||
export let layout = "";
|
||||
@@ -39,6 +40,9 @@
|
||||
response_message = response_data.message;
|
||||
console.log("response:", response_data, "status:", response_status, "message:", response_message);
|
||||
|
||||
// join socket room
|
||||
socket.emit('join', room_name);
|
||||
|
||||
// go to room
|
||||
if (response_status === 200 && response_message === "successfull room creation")
|
||||
layout = "room";
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
rooms = data.rooms;
|
||||
});
|
||||
|
||||
// get room messages
|
||||
function get_room_messages()
|
||||
{
|
||||
console.log("in get_room_messages");
|
||||
@@ -39,6 +40,8 @@
|
||||
//msgs.update(msgs => msgs.concat(data.messages));
|
||||
msgs.update(msgs => msgs = data.messages);
|
||||
});
|
||||
|
||||
// go to room
|
||||
layout = "room";
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script>
|
||||
|
||||
import Button from './Element_button.svelte';
|
||||
import { msgs, user } from './Store_chat';
|
||||
import { msgs, user, socket } from './Store_chat';
|
||||
export let layout = "";
|
||||
export let back = "";
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
rooms = data.rooms;
|
||||
});
|
||||
|
||||
// join the room
|
||||
function join_rooms(evt)
|
||||
{
|
||||
console.log("inside join_rooms");
|
||||
@@ -25,6 +26,7 @@
|
||||
room_name: evt.target.innerText,
|
||||
}
|
||||
|
||||
// join room
|
||||
fetch('/api/v2/chat/join',
|
||||
{
|
||||
method: 'POST',
|
||||
@@ -37,6 +39,10 @@
|
||||
console.log(data);
|
||||
});
|
||||
|
||||
// join socket room
|
||||
socket.emit('join', room_name);
|
||||
|
||||
// get messages from room
|
||||
const messages = fetch('/api/v2/chat/messages')
|
||||
.then(resp => resp.json())
|
||||
.then(data =>
|
||||
@@ -49,9 +55,9 @@
|
||||
});
|
||||
msgs.update(msgs => msgs = data.messages);
|
||||
});
|
||||
|
||||
// go to room
|
||||
layout = "room";
|
||||
/*
|
||||
*/
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user