room load old message but pbm to read them

This commit is contained in:
simplonco
2023-01-08 14:18:57 +01:00
parent c41c7de745
commit c5ed704a62
7 changed files with 143 additions and 116 deletions

View File

@@ -2,7 +2,7 @@ import { Controller, UseGuards, HttpException, HttpStatus, Get, Post, Body, Req,
import { AuthenticateGuard, TwoFactorGuard } from 'src/auth/42/guards/42guards'; import { AuthenticateGuard, TwoFactorGuard } from 'src/auth/42/guards/42guards';
import { ChatService } from './chat.service'; import { ChatService } from './chat.service';
import { User } from 'src/users/entities/user.entity'; import { User } from 'src/users/entities/user.entity';
import { joinRoomDto } from './dto/joinRoom.dto'; import { createRoomDto } from './dto/createRoom.dto';
import { setCurrentRoomDto } from './dto/setCurrentRoom.dto'; import { setCurrentRoomDto } from './dto/setCurrentRoom.dto';
@Controller('chat') @Controller('chat')
@@ -15,28 +15,39 @@ export class ChatController {
@UseGuards(AuthenticateGuard) @UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard) @UseGuards(TwoFactorGuard)
@Get('rooms') @Get('rooms')
async getRooms(@Req() req, @Res() res) async getRooms(@Req() req, @Res() res): Promise<object>
{ {
//console.log("in getRooms"); console.log("- in getRooms controller");
return await this.chatService.getRooms(req.user, res); const rooms = await this.chatService.getRooms(req.user);
return res.status(HttpStatus.OK).json({ rooms: rooms });
} }
@UseGuards(AuthenticateGuard) @UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard) @UseGuards(TwoFactorGuard)
@Get('current') @Get('current')
async setCurrentRoom(@Body() setCurrentRoomDto: setCurrentRoomDto, @Req() req, @Res() res) async setCurrentRoom(@Body() setCurrentRoomDto: setCurrentRoomDto, @Req() req, @Res() res): Promise<object>
{ {
//console.log("in setCurrentRoom"); console.log("- in setCurrentRoom controller");
return await this.chatService.setCurrentRoom(req.user, setCurrentRoomDto.name, res); const response = await this.chatService.setCurrentRoom(req.user, setCurrentRoomDto.name);
return res.status(HttpStatus.OK).json({ message: response });
}
@UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard)
@Post('create')
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);
return res.status(HttpStatus.OK).json({ room_name: createRoomDto.room_name, message: response });
} }
@UseGuards(AuthenticateGuard) @UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard) @UseGuards(TwoFactorGuard)
@Post('join') @Post('join')
async joinRoom(@Body() joinRoomDto: joinRoomDto, @Req() req, @Res() res) async joinRoom(@Body() body)
{ {
//console.log("in joinRoom"); console.log("- in joinRoom controller");
return await this.chatService.addUserToRoom(req.user, joinRoomDto, res);
} }
@UseGuards(AuthenticateGuard) @UseGuards(AuthenticateGuard)
@@ -44,14 +55,17 @@ export class ChatController {
@Post('leave') @Post('leave')
async leaveRoom(@Body() body) async leaveRoom(@Body() body)
{ {
console.log("- in leaveRoom controller");
} }
@UseGuards(AuthenticateGuard) @UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard) @UseGuards(TwoFactorGuard)
@Get('messages') @Get('messages')
async getMessages(@Req() req, @Res() res) async getMessages(@Req() req, @Res() res): Promise<object>
{ {
return this.chatService.getMessagesFromCurrentRoom(req.user, res); console.log("- in getMessages controller");
const messages = await this.chatService.getMessagesFromCurrentRoom(req.user);
return res.status(HttpStatus.OK).json({ messages: messages });
} }
} }

View File

@@ -4,7 +4,7 @@ import { UsersService } from 'src/users/users.service';
import { Chatroom } from './entities/chatroom.entity'; import { Chatroom } from './entities/chatroom.entity';
import { Repository } from 'typeorm'; import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm'; import { InjectRepository } from '@nestjs/typeorm';
import { joinRoomDto } from './dto/joinRoom.dto'; import { createRoomDto } from './dto/createRoom.dto';
import { messagesDto } from './dto/messages.dto'; import { messagesDto } from './dto/messages.dto';
@Injectable() @Injectable()
@@ -24,38 +24,43 @@ export class ChatService {
return new Promise(resolve => setTimeout(resolve, ms)); return new Promise(resolve => setTimeout(resolve, ms));
} }
async getRooms(user: User, @Res() res) async getRooms(user: User): Promise<object>
{ {
console.log("-- in getRooms service");
const rooms = await this.chatroomRepository const rooms = await this.chatroomRepository
.createQueryBuilder('chatroom') .createQueryBuilder('chatroom')
.where(':user_id IN (chatroom.users)', { user_id: user.fortyTwoId }) .where(':user_id IN (chatroom.users)', { user_id: user.fortyTwoId })
.getMany(); .getMany();
return rooms;
return res.status(HttpStatus.OK).json({ rooms: rooms });
} }
async findRoomByName(name: string) async findRoomByName(name: string)
{ {
console.log("-- in findUserByName service");
const room = await this.chatroomRepository const room = await this.chatroomRepository
.createQueryBuilder('chatroom') .createQueryBuilder('chatroom')
.where('chatroom.name = :name', { name: name }) .where('chatroom.name = :name', { name: name })
.getOne(); .getOne();
console.log("room:", room, ", typeof room:", typeof room);
return room; return room;
} }
async findRoomById(id: number, @Res() res) async findRoomById(id: number)
{ {
console.log("-- in findRoomById service");
const room = await this.chatroomRepository const room = await this.chatroomRepository
.createQueryBuilder('chatroom') .createQueryBuilder('chatroom')
.where('chatroom.id = :id', { id: id }) .where('chatroom.id = :id', { id: id })
.getOne(); .getOne();
return res.status(HttpStatus.OK).json({ room: room }); console.log("room:", room, ", typeof room:", typeof room);
return room;
} }
async findUserByName(name: string) async findUserByName(name: string): Promise<object>
{ {
console.log("-- in findUserByName service");
const user = await this.userRepository const user = await this.userRepository
.createQueryBuilder('user') .createQueryBuilder('user')
.where('user.username = :name', { name: name }) .where('user.username = :name', { name: name })
@@ -64,46 +69,50 @@ export class ChatService {
return user; return user;
} }
async setCurrentRoom(user: User, name: string, @Res() res) async setCurrentRoom(user: User, name: string): Promise<string>
{ {
console.log("-- in setCurrentRoom service");
const user_db = await this.usersService.findOneByFourtyTwoId(user.fortyTwoId); const user_db = await this.usersService.findOneByFourtyTwoId(user.fortyTwoId);
user_db.currentRoom = name; user_db.currentRoom = name;
this.userRepository.save(user_db); this.userRepository.save(user_db);
return res.status(HttpStatus.OK).json({ message: `room "${name}" is now current room` }); return `room "${name}" is now current room`;
} }
async addUserToRoom(user: User, joinRoomDto: joinRoomDto, @Res() res) async addUserToRoom(user: User, createRoomDto: createRoomDto): Promise<string>
{ {
console.log("-- in addUserToRoom service");
const room = await this.chatroomRepository const room = await this.chatroomRepository
.createQueryBuilder('chatroom') .createQueryBuilder('chatroom')
.where('chatroom.name = :name', { name: joinRoomDto.room_name }) .where('chatroom.name = :name', { name: createRoomDto.room_name })
.getOne(); .getOne();
if (room) if (room)
throw new HttpException(`This room already exist`, HttpStatus.CONFLICT); throw new HttpException(`This room already exist`, HttpStatus.CONFLICT);
// create chatroom // create chatroom
const newChatroom = new Chatroom(); const newChatroom = new Chatroom();
newChatroom.name = joinRoomDto.room_name; newChatroom.name = createRoomDto.room_name;
newChatroom.type = joinRoomDto.room_type; newChatroom.type = createRoomDto.room_type;
newChatroom.owner = user.fortyTwoId; newChatroom.owner = user.fortyTwoId;
newChatroom.users = [user.fortyTwoId]; newChatroom.users = [user.fortyTwoId];
newChatroom.messages = [{ name: "SERVER", message: `creation of room ${joinRoomDto.room_name}` }]; newChatroom.messages = [{ name: "SERVER", message: `creation of room ${createRoomDto.room_name}` }];
this.chatroomRepository.save(newChatroom); this.chatroomRepository.save(newChatroom);
this.setCurrentRoom(user, joinRoomDto.room_name, res) this.setCurrentRoom(user, createRoomDto.room_name)
return res.status(HttpStatus.OK).json({ room_name: joinRoomDto.room_name, message: "successfull room creation" }); return "successfull room creation";
} }
async removeUserFromRoom(user: User, room_name: string) async removeUserFromRoom(user: User, room_name: string)
{ {
console.log("-- in removeUserFromRoom service");
// get room // get room
// remove user // remove user
} }
async addMessageToCurrentRoom(name: string, message: string) async addMessageToCurrentRoom(name: string, message: string)
{ {
console.log("-- in addMessageToCurrentRoom service");
const user_db = await this.findUserByName(name); const user_db = await this.findUserByName(name);
const currentRoom = await this.findRoomByName(user_db.currentRoom); const currentRoom = await this.findRoomByName(user_db.currentRoom);
let chat_message = { let chat_message = {
@@ -115,11 +124,13 @@ export class ChatService {
this.chatroomRepository.save(currentRoom); this.chatroomRepository.save(currentRoom);
} }
async getMessagesFromCurrentRoom(user: User, @Res() res) async getMessagesFromCurrentRoom(user: User): Promise<object>
{ {
console.log("-- in getMessagesFromCurrentRoom service");
const user_db = await this.usersService.findOneByFourtyTwoId(user.fortyTwoId); const user_db = await this.usersService.findOneByFourtyTwoId(user.fortyTwoId);
const currentRoom = await this.findRoomByName(user_db.currentRoom); const currentRoom = await this.findRoomByName(user_db.currentRoom);
return res.status(HttpStatus.OK).json({ messages: currentRoom.messages });
return currentRoom.messages;
} }
} }

View File

@@ -1,7 +1,7 @@
import { IsBoolean, IsEmpty, IsInt, IsNotEmpty, IsNumber, IsString, IsOptional } from "class-validator"; import { IsBoolean, IsEmpty, IsInt, IsNotEmpty, IsNumber, IsString, IsOptional } from "class-validator";
import { IsNull } from "typeorm"; import { IsNull } from "typeorm";
export class joinRoomDto export class createRoomDto
{ {
@IsString() @IsString()
@IsNotEmpty() @IsNotEmpty()

View File

@@ -3903,7 +3903,7 @@ var app = (function () {
return child_ctx; return child_ctx;
} }
// (45:1) <Button bind:layout new_layout="settings" my_class="settings dots icon"> // (50:1) <Button bind:layout new_layout="settings" my_class="settings dots icon">
function create_default_slot_3$5(ctx) { function create_default_slot_3$5(ctx) {
let t; let t;
@@ -3923,14 +3923,14 @@ var app = (function () {
block, block,
id: create_default_slot_3$5.name, id: create_default_slot_3$5.name,
type: "slot", type: "slot",
source: "(45:1) <Button bind:layout new_layout=\\\"settings\\\" my_class=\\\"settings dots icon\\\">", source: "(50:1) <Button bind:layout new_layout=\\\"settings\\\" my_class=\\\"settings dots icon\\\">",
ctx ctx
}); });
return block; return block;
} }
// (50:1) <Button bind:layout new_layout="new" my_class="new transparent"> // (55:1) <Button bind:layout new_layout="new" my_class="new transparent">
function create_default_slot_2$9(ctx) { function create_default_slot_2$9(ctx) {
let t; let t;
@@ -3950,14 +3950,14 @@ var app = (function () {
block, block,
id: create_default_slot_2$9.name, id: create_default_slot_2$9.name,
type: "slot", type: "slot",
source: "(50:1) <Button bind:layout new_layout=\\\"new\\\" my_class=\\\"new transparent\\\">", source: "(55:1) <Button bind:layout new_layout=\\\"new\\\" my_class=\\\"new transparent\\\">",
ctx ctx
}); });
return block; return block;
} }
// (55:1) <Button bind:layout new_layout="close" my_class="close icon"> // (60:1) <Button bind:layout new_layout="close" my_class="close icon">
function create_default_slot_1$9(ctx) { function create_default_slot_1$9(ctx) {
let t; let t;
@@ -3977,7 +3977,7 @@ var app = (function () {
block, block,
id: create_default_slot_1$9.name, id: create_default_slot_1$9.name,
type: "slot", type: "slot",
source: "(55:1) <Button bind:layout new_layout=\\\"close\\\" my_class=\\\"close icon\\\">", source: "(60:1) <Button bind:layout new_layout=\\\"close\\\" my_class=\\\"close icon\\\">",
ctx ctx
}); });
@@ -4006,7 +4006,7 @@ var app = (function () {
return block; return block;
} }
// (69:3) {:then} // (74:3) {:then}
function create_then_block$1(ctx) { function create_then_block$1(ctx) {
let each_1_anchor; let each_1_anchor;
let current; let current;
@@ -4039,7 +4039,7 @@ var app = (function () {
current = true; current = true;
}, },
p: function update(ctx, dirty) { p: function update(ctx, dirty) {
if (dirty & /*layout, rooms*/ 3) { if (dirty & /*get_room_messages, rooms*/ 10) {
each_value = /*rooms*/ ctx[1]; each_value = /*rooms*/ ctx[1];
validate_each_argument(each_value); validate_each_argument(each_value);
let i; let i;
@@ -4095,14 +4095,14 @@ var app = (function () {
block, block,
id: create_then_block$1.name, id: create_then_block$1.name,
type: "then", type: "then",
source: "(69:3) {:then}", source: "(74:3) {:then}",
ctx ctx
}); });
return block; return block;
} }
// (71:5) <Button bind:layout new_layout="room" my_class="list"> // (76:5) <Button my_class="list" on_click={get_room_messages}>
function create_default_slot$b(ctx) { function create_default_slot$b(ctx) {
let t0_value = /*room*/ ctx[7].name + ""; let t0_value = /*room*/ ctx[7].name + "";
let t0; let t0;
@@ -4130,36 +4130,27 @@ var app = (function () {
block, block,
id: create_default_slot$b.name, id: create_default_slot$b.name,
type: "slot", type: "slot",
source: "(71:5) <Button bind:layout new_layout=\\\"room\\\" my_class=\\\"list\\\">", source: "(76:5) <Button my_class=\\\"list\\\" on_click={get_room_messages}>",
ctx ctx
}); });
return block; return block;
} }
// (70:4) {#each rooms as room} // (75:4) {#each rooms as room}
function create_each_block$5(ctx) { function create_each_block$5(ctx) {
let button; let button;
let updating_layout;
let current; let current;
function button_layout_binding(value) { button = new Chat_button({
/*button_layout_binding*/ ctx[6](value); props: {
}
let button_props = {
new_layout: "room",
my_class: "list", my_class: "list",
on_click: /*get_room_messages*/ ctx[3],
$$slots: { default: [create_default_slot$b] }, $$slots: { default: [create_default_slot$b] },
$$scope: { ctx } $$scope: { ctx }
}; },
$$inline: true
if (/*layout*/ ctx[0] !== void 0) { });
button_props.layout = /*layout*/ ctx[0];
}
button = new Chat_button({ props: button_props, $$inline: true });
binding_callbacks.push(() => bind(button, 'layout', button_layout_binding));
const block = { const block = {
c: function create() { c: function create() {
@@ -4176,12 +4167,6 @@ var app = (function () {
button_changes.$$scope = { dirty, ctx }; button_changes.$$scope = { dirty, ctx };
} }
if (!updating_layout && dirty & /*layout*/ 1) {
updating_layout = true;
button_changes.layout = /*layout*/ ctx[0];
add_flush_callback(() => updating_layout = false);
}
button.$set(button_changes); button.$set(button_changes);
}, },
i: function intro(local) { i: function intro(local) {
@@ -4202,14 +4187,14 @@ var app = (function () {
block, block,
id: create_each_block$5.name, id: create_each_block$5.name,
type: "each", type: "each",
source: "(70:4) {#each rooms as room}", source: "(75:4) {#each rooms as room}",
ctx ctx
}); });
return block; return block;
} }
// (66:21) <!-- promise is pending --> <p>rooms are loaded...</p> {:then} // (71:21) <!-- promise is pending --> <p>rooms are loaded...</p> {:then}
function create_pending_block$1(ctx) { function create_pending_block$1(ctx) {
let p; let p;
@@ -4217,7 +4202,7 @@ var app = (function () {
c: function create() { c: function create() {
p = element("p"); p = element("p");
p.textContent = "rooms are loaded..."; p.textContent = "rooms are loaded...";
add_location(p, file$p, 67, 4, 1409); add_location(p, file$p, 72, 4, 1510);
}, },
m: function mount(target, anchor) { m: function mount(target, anchor) {
insert_dev(target, p, anchor); insert_dev(target, p, anchor);
@@ -4234,7 +4219,7 @@ var app = (function () {
block, block,
id: create_pending_block$1.name, id: create_pending_block$1.name,
type: "pending", type: "pending",
source: "(66:21) <!-- promise is pending --> <p>rooms are loaded...</p> {:then}", source: "(71:21) <!-- promise is pending --> <p>rooms are loaded...</p> {:then}",
ctx ctx
}); });
@@ -4262,7 +4247,7 @@ var app = (function () {
let current; let current;
function button0_layout_binding(value) { function button0_layout_binding(value) {
/*button0_layout_binding*/ ctx[3](value); /*button0_layout_binding*/ ctx[4](value);
} }
let button0_props = { let button0_props = {
@@ -4280,7 +4265,7 @@ var app = (function () {
binding_callbacks.push(() => bind(button0, 'layout', button0_layout_binding)); binding_callbacks.push(() => bind(button0, 'layout', button0_layout_binding));
function button1_layout_binding(value) { function button1_layout_binding(value) {
/*button1_layout_binding*/ ctx[4](value); /*button1_layout_binding*/ ctx[5](value);
} }
let button1_props = { let button1_props = {
@@ -4298,7 +4283,7 @@ var app = (function () {
binding_callbacks.push(() => bind(button1, 'layout', button1_layout_binding)); binding_callbacks.push(() => bind(button1, 'layout', button1_layout_binding));
function button2_layout_binding(value) { function button2_layout_binding(value) {
/*button2_layout_binding*/ ctx[5](value); /*button2_layout_binding*/ ctx[6](value);
} }
let button2_props = { let button2_props = {
@@ -4348,17 +4333,17 @@ var app = (function () {
t6 = space(); t6 = space();
info.block.c(); info.block.c();
attr_dev(p0, "class", "title svelte-1jygwt2"); attr_dev(p0, "class", "title svelte-1jygwt2");
add_location(p0, file$p, 60, 2, 1177); add_location(p0, file$p, 65, 2, 1278);
attr_dev(p1, "class", "__center"); attr_dev(p1, "class", "__center");
add_location(p1, file$p, 63, 4, 1287); add_location(p1, file$p, 68, 4, 1388);
attr_dev(div0, "class", "__show_if_only_child"); attr_dev(div0, "class", "__show_if_only_child");
add_location(div0, file$p, 62, 3, 1248); add_location(div0, file$p, 67, 3, 1349);
attr_dev(div1, "class", "room_list"); attr_dev(div1, "class", "room_list");
add_location(div1, file$p, 61, 2, 1221); add_location(div1, file$p, 66, 2, 1322);
attr_dev(div2, "class", "panel panel_home __border_top svelte-1jygwt2"); attr_dev(div2, "class", "panel panel_home __border_top svelte-1jygwt2");
add_location(div2, file$p, 59, 1, 1131); add_location(div2, file$p, 64, 1, 1232);
attr_dev(div3, "class", "grid_box svelte-1jygwt2"); attr_dev(div3, "class", "grid_box svelte-1jygwt2");
add_location(div3, file$p, 41, 0, 772); add_location(div3, file$p, 46, 0, 873);
}, },
l: function claim(nodes) { l: function claim(nodes) {
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option"); throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
@@ -4468,6 +4453,10 @@ var app = (function () {
return block; return block;
} }
function test() {
console.log("test");
}
function instance$s($$self, $$props, $$invalidate) { function instance$s($$self, $$props, $$invalidate) {
let { $$slots: slots = {}, $$scope } = $$props; let { $$slots: slots = {}, $$scope } = $$props;
validate_slots('Layout_home', slots, []); validate_slots('Layout_home', slots, []);
@@ -4482,11 +4471,22 @@ var app = (function () {
// ask api for the rooms // ask api for the rooms
const get_rooms = fetch('/api/v2/chat/rooms').then(resp => resp.json()).then(data => { const get_rooms = fetch('/api/v2/chat/rooms').then(resp => resp.json()).then(data => {
console.log(data.rooms); console.log("data.rooms:", data.rooms);
for (let room of data.rooms) console.log(room.name); for (let room of data.rooms) console.log(room.name);
$$invalidate(1, rooms = data.rooms); $$invalidate(1, rooms = data.rooms);
}); });
function get_room_messages() {
console.log("in get_room_messages");
fetch('/api/v2/chat/messages').then(resp => resp.json()).then(data => {
console.log(data.messages);
msgs.update(msgs => msgs.concat(data.messages));
});
$$invalidate(0, layout = "room");
}
$$self.$$.on_mount.push(function () { $$self.$$.on_mount.push(function () {
if (layout === undefined && !('layout' in $$props || $$self.$$.bound[$$self.$$.props['layout']])) { if (layout === undefined && !('layout' in $$props || $$self.$$.bound[$$self.$$.props['layout']])) {
console_1$9.warn("<Layout_home> was created without expected prop 'layout'"); console_1$9.warn("<Layout_home> was created without expected prop 'layout'");
@@ -4514,11 +4514,6 @@ var app = (function () {
$$invalidate(0, layout); $$invalidate(0, layout);
} }
function button_layout_binding(value) {
layout = value;
$$invalidate(0, layout);
}
$$self.$$set = $$props => { $$self.$$set = $$props => {
if ('layout' in $$props) $$invalidate(0, layout = $$props.layout); if ('layout' in $$props) $$invalidate(0, layout = $$props.layout);
}; };
@@ -4529,7 +4524,9 @@ var app = (function () {
msgs, msgs,
layout, layout,
rooms, rooms,
get_rooms get_rooms,
get_room_messages,
test
}); });
$$self.$inject_state = $$props => { $$self.$inject_state = $$props => {
@@ -4545,10 +4542,10 @@ var app = (function () {
layout, layout,
rooms, rooms,
get_rooms, get_rooms,
get_room_messages,
button0_layout_binding, button0_layout_binding,
button1_layout_binding, button1_layout_binding,
button2_layout_binding, button2_layout_binding
button_layout_binding
]; ];
} }
@@ -10952,10 +10949,10 @@ var app = (function () {
t1 = space(); t1 = space();
input = element("input"); input = element("input");
attr_dev(p, "class", "svelte-1b1eu8h"); attr_dev(p, "class", "svelte-1b1eu8h");
add_location(p, file$h, 82, 28, 2616); add_location(p, file$h, 82, 28, 2618);
attr_dev(label, "for", "chat_pswd"); attr_dev(label, "for", "chat_pswd");
attr_dev(label, "class", "svelte-1b1eu8h"); attr_dev(label, "class", "svelte-1b1eu8h");
add_location(label, file$h, 82, 5, 2593); add_location(label, file$h, 82, 5, 2595);
attr_dev(input, "id", "chat_pswd"); attr_dev(input, "id", "chat_pswd");
attr_dev(input, "type", "password"); attr_dev(input, "type", "password");
attr_dev(input, "placeholder", "minimum 8 characters"); attr_dev(input, "placeholder", "minimum 8 characters");
@@ -10963,9 +10960,9 @@ var app = (function () {
attr_dev(input, "name", "password"); attr_dev(input, "name", "password");
input.required = true; input.required = true;
attr_dev(input, "class", "svelte-1b1eu8h"); attr_dev(input, "class", "svelte-1b1eu8h");
add_location(input, file$h, 83, 5, 2656); add_location(input, file$h, 83, 5, 2658);
attr_dev(div, "class", "svelte-1b1eu8h"); attr_dev(div, "class", "svelte-1b1eu8h");
add_location(div, file$h, 81, 4, 2582); add_location(div, file$h, 81, 4, 2584);
}, },
m: function mount(target, anchor) { m: function mount(target, anchor) {
insert_dev(target, div, anchor); insert_dev(target, div, anchor);
@@ -11131,17 +11128,17 @@ var app = (function () {
t16 = space(); t16 = space();
input4 = element("input"); input4 = element("input");
attr_dev(p0, "class", "svelte-1b1eu8h"); attr_dev(p0, "class", "svelte-1b1eu8h");
add_location(p0, file$h, 62, 26, 1779); add_location(p0, file$h, 62, 26, 1781);
attr_dev(label0, "for", "chat_name"); attr_dev(label0, "for", "chat_name");
attr_dev(label0, "class", "svelte-1b1eu8h"); attr_dev(label0, "class", "svelte-1b1eu8h");
add_location(label0, file$h, 62, 3, 1756); add_location(label0, file$h, 62, 3, 1758);
attr_dev(input0, "id", "chat_name"); attr_dev(input0, "id", "chat_name");
attr_dev(input0, "name", "room_name"); attr_dev(input0, "name", "room_name");
input0.required = true; input0.required = true;
attr_dev(input0, "class", "svelte-1b1eu8h"); attr_dev(input0, "class", "svelte-1b1eu8h");
add_location(input0, file$h, 63, 3, 1813); add_location(input0, file$h, 63, 3, 1815);
attr_dev(p1, "class", "svelte-1b1eu8h"); attr_dev(p1, "class", "svelte-1b1eu8h");
add_location(p1, file$h, 66, 4, 1956); add_location(p1, file$h, 66, 4, 1958);
attr_dev(input1, "id", "chat_public"); attr_dev(input1, "id", "chat_public");
attr_dev(input1, "type", "radio"); attr_dev(input1, "type", "radio");
attr_dev(input1, "name", "room_type"); attr_dev(input1, "name", "room_type");
@@ -11150,12 +11147,12 @@ var app = (function () {
input1.required = true; input1.required = true;
attr_dev(input1, "class", "svelte-1b1eu8h"); attr_dev(input1, "class", "svelte-1b1eu8h");
/*$$binding_groups*/ ctx[12][0].push(input1); /*$$binding_groups*/ ctx[12][0].push(input1);
add_location(input1, file$h, 67, 4, 1974); add_location(input1, file$h, 67, 4, 1976);
attr_dev(label1, "for", "chat_public"); attr_dev(label1, "for", "chat_public");
attr_dev(label1, "class", "_radio svelte-1b1eu8h"); attr_dev(label1, "class", "_radio svelte-1b1eu8h");
add_location(label1, file$h, 65, 3, 1911); add_location(label1, file$h, 65, 3, 1913);
attr_dev(p2, "class", "svelte-1b1eu8h"); attr_dev(p2, "class", "svelte-1b1eu8h");
add_location(p2, file$h, 71, 4, 2162); add_location(p2, file$h, 71, 4, 2164);
attr_dev(input2, "id", "chat_private"); attr_dev(input2, "id", "chat_private");
attr_dev(input2, "type", "radio"); attr_dev(input2, "type", "radio");
attr_dev(input2, "name", "room_type"); attr_dev(input2, "name", "room_type");
@@ -11164,12 +11161,12 @@ var app = (function () {
input2.required = true; input2.required = true;
attr_dev(input2, "class", "svelte-1b1eu8h"); attr_dev(input2, "class", "svelte-1b1eu8h");
/*$$binding_groups*/ ctx[12][0].push(input2); /*$$binding_groups*/ ctx[12][0].push(input2);
add_location(input2, file$h, 72, 4, 2181); add_location(input2, file$h, 72, 4, 2183);
attr_dev(label2, "for", "chat_private"); attr_dev(label2, "for", "chat_private");
attr_dev(label2, "class", "_radio svelte-1b1eu8h"); attr_dev(label2, "class", "_radio svelte-1b1eu8h");
add_location(label2, file$h, 70, 3, 2116); add_location(label2, file$h, 70, 3, 2118);
attr_dev(p3, "class", "svelte-1b1eu8h"); attr_dev(p3, "class", "svelte-1b1eu8h");
add_location(p3, file$h, 76, 4, 2375); add_location(p3, file$h, 76, 4, 2377);
attr_dev(input3, "id", "chat_protected"); attr_dev(input3, "id", "chat_protected");
attr_dev(input3, "type", "radio"); attr_dev(input3, "type", "radio");
attr_dev(input3, "name", "room_type"); attr_dev(input3, "name", "room_type");
@@ -11178,20 +11175,20 @@ var app = (function () {
input3.required = true; input3.required = true;
attr_dev(input3, "class", "svelte-1b1eu8h"); attr_dev(input3, "class", "svelte-1b1eu8h");
/*$$binding_groups*/ ctx[12][0].push(input3); /*$$binding_groups*/ ctx[12][0].push(input3);
add_location(input3, file$h, 77, 4, 2396); add_location(input3, file$h, 77, 4, 2398);
attr_dev(label3, "for", "chat_protected"); attr_dev(label3, "for", "chat_protected");
attr_dev(label3, "class", "_radio svelte-1b1eu8h"); attr_dev(label3, "class", "_radio svelte-1b1eu8h");
add_location(label3, file$h, 75, 3, 2327); add_location(label3, file$h, 75, 3, 2329);
attr_dev(input4, "type", "submit"); attr_dev(input4, "type", "submit");
input4.value = "⮡"; input4.value = "⮡";
attr_dev(input4, "class", "svelte-1b1eu8h"); attr_dev(input4, "class", "svelte-1b1eu8h");
add_location(input4, file$h, 86, 3, 2820); add_location(input4, file$h, 86, 3, 2822);
attr_dev(form, "class", "svelte-1b1eu8h"); attr_dev(form, "class", "svelte-1b1eu8h");
add_location(form, file$h, 57, 2, 1605); add_location(form, file$h, 57, 2, 1607);
attr_dev(div0, "class", "panel panel_create __border_top svelte-1b1eu8h"); attr_dev(div0, "class", "panel panel_create __border_top svelte-1b1eu8h");
add_location(div0, file$h, 56, 1, 1557); add_location(div0, file$h, 56, 1, 1559);
attr_dev(div1, "class", "grid_box svelte-1b1eu8h"); attr_dev(div1, "class", "grid_box svelte-1b1eu8h");
add_location(div1, file$h, 38, 0, 1212); add_location(div1, file$h, 38, 0, 1214);
}, },
l: function claim(nodes) { l: function claim(nodes) {
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option"); throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
@@ -11398,7 +11395,7 @@ var app = (function () {
console.log("formData:", formData); console.log("formData:", formData);
// send the new room // send the new room
const response = await fetch('/api/v2/chat/join', { const response = await fetch('/api/v2/chat/create', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData) body: JSON.stringify(formData)

File diff suppressed because one or more lines are too long

View File

@@ -27,7 +27,7 @@
console.log("formData:", formData); console.log("formData:", formData);
// send the new room // send the new room
const response = await fetch('/api/v2/chat/join', { const response = await fetch('/api/v2/chat/create', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData), body: JSON.stringify(formData),

View File

@@ -18,23 +18,28 @@
.then(resp => resp.json()) .then(resp => resp.json())
.then(data => .then(data =>
{ {
console.log(data.rooms); console.log("data.rooms:", data.rooms);
for (let room of data.rooms) for (let room of data.rooms)
console.log(room.name); console.log(room.name);
rooms = data.rooms; rooms = data.rooms;
}); });
/*
function get_room_messages() function get_room_messages()
{ {
console.log("in get_room_messages");
const messages = fetch('/api/v2/chat/messages') const messages = fetch('/api/v2/chat/messages')
.then(resp => resp.json()) .then(resp => resp.json())
.then(data => .then(data =>
{ {
console.log(data.messages); console.log(data.messages);
msgs.update(msgs => [...msgs, { name: name, message: message }]); msgs.update(msgs => msgs.concat(data.messages));
}); });
layout = "room";
} }
function test() {
console.log("test");
}
/*
*/ */
</script> </script>
@@ -68,7 +73,7 @@
<p>rooms are loaded...</p> <p>rooms are loaded...</p>
{:then} {:then}
{#each rooms as room} {#each rooms as room}
<Button bind:layout new_layout="room" my_class="list"> <Button my_class="list" on_click={get_room_messages}>
{room.name} {room.name}
</Button> </Button>
{/each} {/each}