wip db request with array not working
This commit is contained in:
@@ -3,6 +3,7 @@ import { AuthenticateGuard, TwoFactorGuard } from 'src/auth/42/guards/42guards';
|
||||
import { ChatService } from './chat.service';
|
||||
import { User } from 'src/users/entities/user.entity';
|
||||
import { createRoomDto } from './dto/createRoom.dto';
|
||||
import { joinRoomDto } from './dto/joinRoom.dto';
|
||||
import { setCurrentRoomDto } from './dto/setCurrentRoom.dto';
|
||||
|
||||
@Controller('chat')
|
||||
@@ -48,16 +49,18 @@ export class ChatController {
|
||||
async createRoom(@Body() createRoomDto: createRoomDto, @Req() req, @Res() res): Promise<object>
|
||||
{
|
||||
console.log("- in createRoom controller");
|
||||
const response = await this.chatService.addUserToRoom(req.user, createRoomDto);
|
||||
const response = await this.chatService.addUserToNewRoom(req.user, createRoomDto);
|
||||
return res.status(HttpStatus.OK).json({ room_name: createRoomDto.room_name, message: response });
|
||||
}
|
||||
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Post('join')
|
||||
async joinRoom(@Body() body)
|
||||
async joinRoom(@Body() joinRoomDto: joinRoomDto, @Req() req, @Res() res): Promise<object>
|
||||
{
|
||||
console.log("- in joinRoom controller");
|
||||
const response = await this.chatService.addUserToRoom(req.user, joinRoomDto);
|
||||
return res.status(HttpStatus.OK).json({ room_name: joinRoomDto.room_name, message: response });
|
||||
}
|
||||
|
||||
@UseGuards(AuthenticateGuard)
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Chatroom } from './entities/chatroom.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { createRoomDto } from './dto/createRoom.dto';
|
||||
import { joinRoomDto } from './dto/joinRoom.dto';
|
||||
import { messagesDto } from './dto/messages.dto';
|
||||
|
||||
@Injectable()
|
||||
@@ -29,7 +30,17 @@ export class ChatService {
|
||||
console.log("-- in getMyRooms service");
|
||||
const rooms = await this.chatroomRepository
|
||||
.createQueryBuilder('chatroom')
|
||||
.where(':user_id IN (chatroom.users)', { user_id: user.fortyTwoId })
|
||||
.where(':user_name ANY(chatroom.users)', { user_name: user.username })
|
||||
.getMany();
|
||||
|
||||
return rooms;
|
||||
}
|
||||
|
||||
async getAllRooms()
|
||||
{
|
||||
console.log("-- in getAllRooms service");
|
||||
const rooms = await this.chatroomRepository
|
||||
.createQueryBuilder('chatroom')
|
||||
.getMany();
|
||||
|
||||
return rooms;
|
||||
@@ -38,11 +49,11 @@ export class ChatService {
|
||||
async getAllNotMyRooms(user: User)
|
||||
{
|
||||
console.log("-- in getAllNotMyRooms service");
|
||||
const user_db = await this.usersService.findOneByFourtyTwoId(user.fortyTwoId);
|
||||
const user_db = await this.findUserByName(user.username);
|
||||
const rooms = await this.chatroomRepository
|
||||
.createQueryBuilder('chatroom')
|
||||
.where('chatroom.type != :type', { type: 'private' })
|
||||
.andWhere(':user_id NOT IN (chatroom.users)', { user_id: user.fortyTwoId })
|
||||
.andWhere(':user_name NOT IN (chatroom.users)', { user_name: user.username })
|
||||
.getMany();
|
||||
//const users = await this.findAllUsers();
|
||||
//let allRooms = [...rooms, ...users];
|
||||
@@ -102,20 +113,17 @@ export class ChatService {
|
||||
async setCurrentRoom(user: User, name: string)
|
||||
{
|
||||
console.log("-- in setCurrentRoom service");
|
||||
const user_db = await this.usersService.findOneByFourtyTwoId(user.fortyTwoId);
|
||||
const user_db = await this.findUserByName(user.username);
|
||||
user_db.currentRoom = name;
|
||||
this.userRepository.save(user_db);
|
||||
|
||||
return `room "${name}" is now current room`;
|
||||
}
|
||||
|
||||
async addUserToRoom(user: User, createRoomDto: createRoomDto)
|
||||
async addUserToNewRoom(user: User, createRoomDto: createRoomDto)
|
||||
{
|
||||
console.log("-- in addUserToRoom service");
|
||||
const room = await this.chatroomRepository
|
||||
.createQueryBuilder('chatroom')
|
||||
.where('chatroom.name = :name', { name: createRoomDto.room_name })
|
||||
.getOne();
|
||||
const room = await this.findRoomByName(createRoomDto.room_name);
|
||||
if (room)
|
||||
throw new HttpException(`This room already exist`, HttpStatus.CONFLICT);
|
||||
|
||||
@@ -123,8 +131,8 @@ export class ChatService {
|
||||
const newChatroom = new Chatroom();
|
||||
newChatroom.name = createRoomDto.room_name;
|
||||
newChatroom.type = createRoomDto.room_type;
|
||||
newChatroom.owner = user.fortyTwoId;
|
||||
newChatroom.users = [user.fortyTwoId];
|
||||
newChatroom.owner = user.username;
|
||||
newChatroom.users = [user.username];
|
||||
newChatroom.messages = [{ name: "SERVER", message: `creation of room ${createRoomDto.room_name}` }];
|
||||
this.chatroomRepository.save(newChatroom);
|
||||
|
||||
@@ -133,6 +141,27 @@ export class ChatService {
|
||||
return "successfull room creation";
|
||||
}
|
||||
|
||||
async addUserToRoom(user: User, joinRoomDto: joinRoomDto)
|
||||
{
|
||||
console.log("-- in addUserToRoom service");
|
||||
const room = await this.findRoomByName(joinRoomDto.room_name);
|
||||
if (room.users.includes(user.username))
|
||||
throw new HttpException(`your have already join this room`, HttpStatus.CONFLICT);
|
||||
|
||||
// update room with new user
|
||||
room.users.push(user.username);
|
||||
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 removeUserFromRoom(user: User, room_name: string)
|
||||
{
|
||||
console.log("-- in removeUserFromRoom service");
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { IsBoolean, IsEmpty, IsInt, IsNotEmpty, IsNumber, IsString, IsOptional } from "class-validator";
|
||||
import { IsNull } from "typeorm";
|
||||
|
||||
export class joinRoomDto
|
||||
{
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
room_name: string;
|
||||
}
|
||||
|
||||
@@ -27,10 +27,10 @@ export class Chatroom {
|
||||
// users: User[];
|
||||
|
||||
@Column()
|
||||
owner: string; // fortytwo id
|
||||
owner: string; // name
|
||||
|
||||
@Column("simple-array")
|
||||
users: string[]; // fortytwo id
|
||||
users: string[]; // names
|
||||
|
||||
@Column("json")
|
||||
messages: { name: string, message: string }[];
|
||||
|
||||
@@ -3896,11 +3896,9 @@ var app = (function () {
|
||||
}
|
||||
|
||||
let msgs = writable([]);
|
||||
|
||||
let user;
|
||||
let socket$1;
|
||||
|
||||
function set_user(new_user) { user = new_user; }
|
||||
function set_user(new_user) { user = new_user; }
|
||||
function set_socket(new_socket) { socket$1 = new_socket; }
|
||||
|
||||
/* src/pieces/chat/Layout_home.svelte generated by Svelte v3.53.1 */
|
||||
@@ -5406,7 +5404,7 @@ var app = (function () {
|
||||
return child_ctx;
|
||||
}
|
||||
|
||||
// (30:1) <Button bind:layout new_layout={back} my_class="back icon" my_title="go back {back}">
|
||||
// (67: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;
|
||||
|
||||
@@ -5426,14 +5424,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot_4$2.name,
|
||||
type: "slot",
|
||||
source: "(30:1) <Button bind:layout new_layout={back} my_class=\\\"back icon\\\" my_title=\\\"go back {back}\\\">",
|
||||
source: "(67:1) <Button bind:layout new_layout={back} my_class=\\\"back icon\\\" my_title=\\\"go back {back}\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (35:1) <Button my_class="new deactivate">
|
||||
// (72:1) <Button my_class="new deactivate">
|
||||
function create_default_slot_3$3(ctx) {
|
||||
let t;
|
||||
|
||||
@@ -5453,14 +5451,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot_3$3.name,
|
||||
type: "slot",
|
||||
source: "(35:1) <Button my_class=\\\"new deactivate\\\">",
|
||||
source: "(72:1) <Button my_class=\\\"new deactivate\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (40:1) <Button bind:layout new_layout="close" my_class="close icon">
|
||||
// (77:1) <Button bind:layout new_layout="close" my_class="close icon">
|
||||
function create_default_slot_2$7(ctx) {
|
||||
let t;
|
||||
|
||||
@@ -5480,14 +5478,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot_2$7.name,
|
||||
type: "slot",
|
||||
source: "(40:1) <Button bind:layout new_layout=\\\"close\\\" my_class=\\\"close icon\\\">",
|
||||
source: "(77:1) <Button bind:layout new_layout=\\\"close\\\" my_class=\\\"close icon\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (46:2) <Button bind:layout new_layout="create" my_class="create">
|
||||
// (83:2) <Button bind:layout new_layout="create" my_class="create">
|
||||
function create_default_slot_1$7(ctx) {
|
||||
let t;
|
||||
|
||||
@@ -5507,7 +5505,7 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot_1$7.name,
|
||||
type: "slot",
|
||||
source: "(46:2) <Button bind:layout new_layout=\\\"create\\\" my_class=\\\"create\\\">",
|
||||
source: "(83:2) <Button bind:layout new_layout=\\\"create\\\" my_class=\\\"create\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
@@ -5536,7 +5534,7 @@ var app = (function () {
|
||||
return block;
|
||||
}
|
||||
|
||||
// (57:3) {:then}
|
||||
// (94:3) {:then}
|
||||
function create_then_block$1(ctx) {
|
||||
let each_1_anchor;
|
||||
let current;
|
||||
@@ -5625,14 +5623,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_then_block$1.name,
|
||||
type: "then",
|
||||
source: "(57:3) {:then}",
|
||||
source: "(94:3) {:then}",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (59:5) <Button my_class="list" on_click={join_rooms}>
|
||||
// (96:5) <Button my_class="list" on_click={join_rooms}>
|
||||
function create_default_slot$9(ctx) {
|
||||
let t0_value = /*room*/ ctx[7].name + "";
|
||||
let t0;
|
||||
@@ -5660,14 +5658,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot$9.name,
|
||||
type: "slot",
|
||||
source: "(59:5) <Button my_class=\\\"list\\\" on_click={join_rooms}>",
|
||||
source: "(96:5) <Button my_class=\\\"list\\\" on_click={join_rooms}>",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (58:4) {#each rooms as room}
|
||||
// (95:4) {#each rooms as room}
|
||||
function create_each_block$4(ctx) {
|
||||
let button;
|
||||
let current;
|
||||
@@ -5717,14 +5715,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_each_block$4.name,
|
||||
type: "each",
|
||||
source: "(58:4) {#each rooms as room}",
|
||||
source: "(95:4) {#each rooms as room}",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (54:21) <!-- promise is pending --> <p>rooms are loaded...</p> {:then}
|
||||
// (91:21) <!-- promise is pending --> <p>rooms are loaded...</p> {:then}
|
||||
function create_pending_block$1(ctx) {
|
||||
let p;
|
||||
|
||||
@@ -5732,7 +5730,7 @@ var app = (function () {
|
||||
c: function create() {
|
||||
p = element("p");
|
||||
p.textContent = "rooms are loaded...";
|
||||
add_location(p, file$m, 55, 4, 1128);
|
||||
add_location(p, file$m, 92, 4, 1943);
|
||||
},
|
||||
m: function mount(target, anchor) {
|
||||
insert_dev(target, p, anchor);
|
||||
@@ -5749,7 +5747,7 @@ var app = (function () {
|
||||
block,
|
||||
id: create_pending_block$1.name,
|
||||
type: "pending",
|
||||
source: "(54:21) <!-- promise is pending --> <p>rooms are loaded...</p> {:then}",
|
||||
source: "(91:21) <!-- promise is pending --> <p>rooms are loaded...</p> {:then}",
|
||||
ctx
|
||||
});
|
||||
|
||||
@@ -5876,17 +5874,17 @@ var app = (function () {
|
||||
p1.textContent = "/ there are no public rooms yet /";
|
||||
t7 = space();
|
||||
info.block.c();
|
||||
add_location(p0, file$m, 48, 2, 912);
|
||||
add_location(p0, file$m, 85, 2, 1727);
|
||||
attr_dev(p1, "class", "__center");
|
||||
add_location(p1, file$m, 51, 4, 1002);
|
||||
add_location(p1, file$m, 88, 4, 1817);
|
||||
attr_dev(div0, "class", "__show_if_only_child");
|
||||
add_location(div0, file$m, 50, 3, 963);
|
||||
add_location(div0, file$m, 87, 3, 1778);
|
||||
attr_dev(div1, "class", "public_rooms");
|
||||
add_location(div1, file$m, 49, 2, 933);
|
||||
add_location(div1, file$m, 86, 2, 1748);
|
||||
attr_dev(div2, "class", "panel panel_new __border_top");
|
||||
add_location(div2, file$m, 44, 1, 784);
|
||||
add_location(div2, file$m, 81, 1, 1599);
|
||||
attr_dev(div3, "class", "grid_box svelte-1b4c0qx");
|
||||
add_location(div3, file$m, 26, 0, 451);
|
||||
add_location(div3, file$m, 63, 0, 1266);
|
||||
},
|
||||
l: function claim(nodes) {
|
||||
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
|
||||
@@ -6010,9 +6008,37 @@ var app = (function () {
|
||||
return block;
|
||||
}
|
||||
|
||||
function join_rooms() {
|
||||
function join_rooms(evt) {
|
||||
console.log("inside join_rooms");
|
||||
}
|
||||
let room_name = { room_name: evt.target.innerText };
|
||||
|
||||
fetch('/api/v2/chat/join', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(room_name)
|
||||
}).then(resp => resp.json()).then(data => {
|
||||
console.log(data);
|
||||
}); // data.messages.forEach(function(item) {
|
||||
// if (item.name === user.username) {
|
||||
// item.name = "me";
|
||||
// }
|
||||
// });
|
||||
} // msgs.update(msgs => msgs.concat(data.messages));
|
||||
/*
|
||||
const messages = fetch('/api/v2/chat/messages')
|
||||
.then(resp => resp.json())
|
||||
.then(data =>
|
||||
{
|
||||
console.log(data.messages);
|
||||
data.messages.forEach(function(item) {
|
||||
if (item.name === user.username) {
|
||||
item.name = "me";
|
||||
}
|
||||
});
|
||||
msgs.update(msgs => msgs.concat(data.messages));
|
||||
});
|
||||
layout = "room";
|
||||
*/
|
||||
|
||||
function instance$p($$self, $$props, $$invalidate) {
|
||||
let { $$slots: slots = {}, $$scope } = $$props;
|
||||
@@ -7642,7 +7668,7 @@ var app = (function () {
|
||||
const { console: console_1$8 } = globals;
|
||||
const file$h = "src/pieces/chat/Layout_create.svelte";
|
||||
|
||||
// (42:1) <Button bind:layout new_layout={back} my_class="back icon" my_title="go back {back}">
|
||||
// (41: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;
|
||||
|
||||
@@ -7662,14 +7688,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot_2$3.name,
|
||||
type: "slot",
|
||||
source: "(42:1) <Button bind:layout new_layout={back} my_class=\\\"back icon\\\" my_title=\\\"go back {back}\\\">",
|
||||
source: "(41:1) <Button bind:layout new_layout={back} my_class=\\\"back icon\\\" my_title=\\\"go back {back}\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (47:1) <Button my_class="create deactivate">
|
||||
// (46:1) <Button my_class="create deactivate">
|
||||
function create_default_slot_1$3(ctx) {
|
||||
let t;
|
||||
|
||||
@@ -7689,14 +7715,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot_1$3.name,
|
||||
type: "slot",
|
||||
source: "(47:1) <Button my_class=\\\"create deactivate\\\">",
|
||||
source: "(46:1) <Button my_class=\\\"create deactivate\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (52:1) <Button bind:layout new_layout="close" my_class="close icon">
|
||||
// (51:1) <Button bind:layout new_layout="close" my_class="close icon">
|
||||
function create_default_slot$5(ctx) {
|
||||
let t;
|
||||
|
||||
@@ -7716,14 +7742,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_default_slot$5.name,
|
||||
type: "slot",
|
||||
source: "(52:1) <Button bind:layout new_layout=\\\"close\\\" my_class=\\\"close icon\\\">",
|
||||
source: "(51:1) <Button bind:layout new_layout=\\\"close\\\" my_class=\\\"close icon\\\">",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (59:3) {#if response_status >= 300}
|
||||
// (58:3) {#if response_status >= 300}
|
||||
function create_if_block_1$5(ctx) {
|
||||
let warning;
|
||||
let current;
|
||||
@@ -7764,14 +7790,14 @@ var app = (function () {
|
||||
block,
|
||||
id: create_if_block_1$5.name,
|
||||
type: "if",
|
||||
source: "(59:3) {#if response_status >= 300}",
|
||||
source: "(58:3) {#if response_status >= 300}",
|
||||
ctx
|
||||
});
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
// (81:3) {#if room_type === 'protected'}
|
||||
// (80:3) {#if room_type === 'protected'}
|
||||
function create_if_block$b(ctx) {
|
||||
let div;
|
||||
let label;
|
||||
@@ -7790,10 +7816,10 @@ var app = (function () {
|
||||
t1 = space();
|
||||
input = element("input");
|
||||
attr_dev(p, "class", "svelte-1ulnmwp");
|
||||
add_location(p, file$h, 82, 28, 2634);
|
||||
add_location(p, file$h, 81, 28, 2596);
|
||||
attr_dev(label, "for", "chat_pswd");
|
||||
attr_dev(label, "class", "svelte-1ulnmwp");
|
||||
add_location(label, file$h, 82, 5, 2611);
|
||||
add_location(label, file$h, 81, 5, 2573);
|
||||
attr_dev(input, "id", "chat_pswd");
|
||||
attr_dev(input, "type", "password");
|
||||
attr_dev(input, "placeholder", "minimum 8 characters");
|
||||
@@ -7801,9 +7827,9 @@ var app = (function () {
|
||||
attr_dev(input, "name", "password");
|
||||
input.required = true;
|
||||
attr_dev(input, "class", "svelte-1ulnmwp");
|
||||
add_location(input, file$h, 83, 5, 2674);
|
||||
add_location(input, file$h, 82, 5, 2636);
|
||||
attr_dev(div, "class", "svelte-1ulnmwp");
|
||||
add_location(div, file$h, 81, 4, 2600);
|
||||
add_location(div, file$h, 80, 4, 2562);
|
||||
},
|
||||
m: function mount(target, anchor) {
|
||||
insert_dev(target, div, anchor);
|
||||
@@ -7834,7 +7860,7 @@ var app = (function () {
|
||||
block,
|
||||
id: create_if_block$b.name,
|
||||
type: "if",
|
||||
source: "(81:3) {#if room_type === 'protected'}",
|
||||
source: "(80:3) {#if room_type === 'protected'}",
|
||||
ctx
|
||||
});
|
||||
|
||||
@@ -7969,17 +7995,17 @@ var app = (function () {
|
||||
t16 = space();
|
||||
input4 = element("input");
|
||||
attr_dev(p0, "class", "svelte-1ulnmwp");
|
||||
add_location(p0, file$h, 62, 26, 1787);
|
||||
add_location(p0, file$h, 61, 26, 1749);
|
||||
attr_dev(label0, "for", "chat_name");
|
||||
attr_dev(label0, "class", "svelte-1ulnmwp");
|
||||
add_location(label0, file$h, 62, 3, 1764);
|
||||
add_location(label0, file$h, 61, 3, 1726);
|
||||
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, 63, 3, 1821);
|
||||
add_location(input0, file$h, 62, 3, 1783);
|
||||
attr_dev(p1, "class", "svelte-1ulnmwp");
|
||||
add_location(p1, file$h, 66, 4, 1964);
|
||||
add_location(p1, file$h, 65, 4, 1926);
|
||||
attr_dev(input1, "id", "chat_public");
|
||||
attr_dev(input1, "type", "radio");
|
||||
attr_dev(input1, "name", "room_type");
|
||||
@@ -7988,12 +8014,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, 67, 4, 1982);
|
||||
add_location(input1, file$h, 66, 4, 1944);
|
||||
attr_dev(label1, "for", "chat_public");
|
||||
attr_dev(label1, "class", "_radio svelte-1ulnmwp");
|
||||
add_location(label1, file$h, 65, 3, 1919);
|
||||
add_location(label1, file$h, 64, 3, 1881);
|
||||
attr_dev(p2, "class", "svelte-1ulnmwp");
|
||||
add_location(p2, file$h, 71, 4, 2175);
|
||||
add_location(p2, file$h, 70, 4, 2137);
|
||||
attr_dev(input2, "id", "chat_private");
|
||||
attr_dev(input2, "type", "radio");
|
||||
attr_dev(input2, "name", "room_type");
|
||||
@@ -8002,12 +8028,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, 72, 4, 2194);
|
||||
add_location(input2, file$h, 71, 4, 2156);
|
||||
attr_dev(label2, "for", "chat_private");
|
||||
attr_dev(label2, "class", "_radio hide svelte-1ulnmwp");
|
||||
add_location(label2, file$h, 70, 3, 2124);
|
||||
add_location(label2, file$h, 69, 3, 2086);
|
||||
attr_dev(p3, "class", "svelte-1ulnmwp");
|
||||
add_location(p3, file$h, 76, 4, 2393);
|
||||
add_location(p3, file$h, 75, 4, 2355);
|
||||
attr_dev(input3, "id", "chat_protected");
|
||||
attr_dev(input3, "type", "radio");
|
||||
attr_dev(input3, "name", "room_type");
|
||||
@@ -8016,20 +8042,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, 77, 4, 2414);
|
||||
add_location(input3, file$h, 76, 4, 2376);
|
||||
attr_dev(label3, "for", "chat_protected");
|
||||
attr_dev(label3, "class", "_radio hide svelte-1ulnmwp");
|
||||
add_location(label3, file$h, 75, 3, 2340);
|
||||
add_location(label3, file$h, 74, 3, 2302);
|
||||
attr_dev(input4, "type", "submit");
|
||||
input4.value = "⮡";
|
||||
attr_dev(input4, "class", "svelte-1ulnmwp");
|
||||
add_location(input4, file$h, 86, 3, 2838);
|
||||
add_location(input4, file$h, 85, 3, 2800);
|
||||
attr_dev(form, "class", "svelte-1ulnmwp");
|
||||
add_location(form, file$h, 57, 2, 1613);
|
||||
add_location(form, file$h, 56, 2, 1575);
|
||||
attr_dev(div0, "class", "panel panel_create __border_top svelte-1ulnmwp");
|
||||
add_location(div0, file$h, 56, 1, 1565);
|
||||
add_location(div0, file$h, 55, 1, 1527);
|
||||
attr_dev(div1, "class", "grid_box svelte-1ulnmwp");
|
||||
add_location(div1, file$h, 38, 0, 1220);
|
||||
add_location(div1, file$h, 37, 0, 1182);
|
||||
},
|
||||
l: function claim(nodes) {
|
||||
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
|
||||
@@ -8232,7 +8258,7 @@ var app = (function () {
|
||||
async function handleSubmit(evt) {
|
||||
let formIsValid = evt.target.checkValidity();
|
||||
if (!formIsValid) return;
|
||||
let formData = { room_name, room_type, room_password };
|
||||
let formData = { room_name, room_type };
|
||||
console.log("formData:", formData);
|
||||
|
||||
// send the new room
|
||||
@@ -14954,54 +14980,44 @@ var app = (function () {
|
||||
connect: lookup,
|
||||
});
|
||||
|
||||
function socket_events(socket)
|
||||
{
|
||||
socket.on('message', function(from, message)
|
||||
{
|
||||
console.log("received msg:", message, from);
|
||||
if (from === user.username)
|
||||
from = "me";
|
||||
msgs.update(msgs => [...msgs, { name: from, message: message }]);
|
||||
});
|
||||
function socket_events(socket) {
|
||||
socket.on('message', function (from, message) {
|
||||
console.log("received msg:", message, from);
|
||||
if (from === user.username)
|
||||
from = "me";
|
||||
msgs.update(msgs => [...msgs, { name: from, message: message }]);
|
||||
});
|
||||
}
|
||||
|
||||
function connection_states(socket)
|
||||
{
|
||||
socket.on('connect', function(){ console.log("socket.io connected"); });
|
||||
socket.on('disconnect', function(){ console.log("socket.io disconnected"); });
|
||||
socket.on('connect_error', function(){ console.log("socket.io connect_error"); });
|
||||
socket.on('connect_timeout', function(){ console.log("socket.io connect_timeout"); });
|
||||
socket.on('error', function(){ console.log("socket.io error"); });
|
||||
socket.on('reconnect', function(){ console.log("socket.io reconnect"); });
|
||||
socket.on('reconnect_attempt', function(){ console.log("socket.io reconnect_attempt"); });
|
||||
socket.on('reconnecting', function(){ console.log("socket.io reconnecting"); });
|
||||
socket.on('reconnect_error', function(){ console.log("socket.io reconnect_error"); });
|
||||
socket.on('reconnect_failed', function(){ console.log("socket.io reconnect_failed"); });
|
||||
socket.on('ping', function(){ console.log("socket.io ping"); });
|
||||
socket.on('pong', function(){ console.log("socket.io pong"); });
|
||||
function connection_states(socket) {
|
||||
socket.on('connect', function () { console.log("socket.io connected"); });
|
||||
socket.on('disconnect', function () { console.log("socket.io disconnected"); });
|
||||
socket.on('connect_error', function () { console.log("socket.io connect_error"); });
|
||||
socket.on('connect_timeout', function () { console.log("socket.io connect_timeout"); });
|
||||
socket.on('error', function () { console.log("socket.io error"); });
|
||||
socket.on('reconnect', function () { console.log("socket.io reconnect"); });
|
||||
socket.on('reconnect_attempt', function () { console.log("socket.io reconnect_attempt"); });
|
||||
socket.on('reconnecting', function () { console.log("socket.io reconnecting"); });
|
||||
socket.on('reconnect_error', function () { console.log("socket.io reconnect_error"); });
|
||||
socket.on('reconnect_failed', function () { console.log("socket.io reconnect_failed"); });
|
||||
socket.on('ping', function () { console.log("socket.io ping"); });
|
||||
socket.on('pong', function () { console.log("socket.io pong"); });
|
||||
}
|
||||
|
||||
const address = `http://${'transcendance'}:${'8080'}`;
|
||||
|
||||
async function init_socket()
|
||||
{
|
||||
const response = await fetch(`${address}/api/v2/user`);
|
||||
const response_data = await response.json();
|
||||
|
||||
set_user(response_data);
|
||||
|
||||
let socket = await lookup(address,
|
||||
{
|
||||
path: '/chat',
|
||||
query:
|
||||
{
|
||||
username: response_data.username,
|
||||
},
|
||||
});
|
||||
set_socket(socket);
|
||||
|
||||
connection_states(socket);
|
||||
socket_events(socket);
|
||||
async function init_socket() {
|
||||
const response = await fetch(`${address}/api/v2/user`);
|
||||
const response_data = await response.json();
|
||||
set_user(response_data);
|
||||
let socket = await lookup(address, {
|
||||
path: '/chat',
|
||||
query: {
|
||||
username: response_data.username,
|
||||
},
|
||||
});
|
||||
set_socket(socket);
|
||||
connection_states(socket);
|
||||
socket_events(socket);
|
||||
}
|
||||
|
||||
/* src/pieces/chat/Chat.svelte generated by Svelte v3.53.1 */
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -22,7 +22,6 @@
|
||||
let formData = {
|
||||
room_name: room_name,
|
||||
room_type: room_type,
|
||||
room_password: room_password,
|
||||
};
|
||||
console.log("formData:", formData);
|
||||
|
||||
|
||||
@@ -17,9 +17,46 @@
|
||||
rooms = data.rooms;
|
||||
});
|
||||
|
||||
function join_rooms()
|
||||
function join_rooms(evt)
|
||||
{
|
||||
console.log("inside join_rooms");
|
||||
let room_name = {
|
||||
room_name: evt.target.innerText,
|
||||
}
|
||||
|
||||
const messages = fetch('/api/v2/chat/join',
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(room_name),
|
||||
})
|
||||
.then(resp => resp.json())
|
||||
.then(data =>
|
||||
{
|
||||
console.log(data);
|
||||
// data.messages.forEach(function(item) {
|
||||
// if (item.name === user.username) {
|
||||
// item.name = "me";
|
||||
// }
|
||||
// });
|
||||
// msgs.update(msgs => msgs.concat(data.messages));
|
||||
});
|
||||
|
||||
/*
|
||||
const messages = fetch('/api/v2/chat/messages')
|
||||
.then(resp => resp.json())
|
||||
.then(data =>
|
||||
{
|
||||
console.log(data.messages);
|
||||
data.messages.forEach(function(item) {
|
||||
if (item.name === user.username) {
|
||||
item.name = "me";
|
||||
}
|
||||
});
|
||||
msgs.update(msgs => msgs.concat(data.messages));
|
||||
});
|
||||
layout = "room";
|
||||
*/
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user