rooms have name

This commit is contained in:
hugogogo
2023-01-09 16:29:27 +01:00
parent e71e555ea4
commit e23699dd51
6 changed files with 63 additions and 48 deletions

View File

@@ -30,7 +30,7 @@ export class ChatGateway
} }
@SubscribeMessage('join') @SubscribeMessage('join')
joinRoom(@ConnectedSocket() socket, @MessageBody() room_name: string): void async joinRoom(@ConnectedSocket() socket, @MessageBody() room_name: string): Promise<void>
{ {
console.log('- in joinRoom gateway'); console.log('- in joinRoom gateway');
socket.join(room_name); socket.join(room_name);
@@ -41,7 +41,9 @@ export class ChatGateway
{ {
console.log('- in handleMessage gateway'); console.log('- in handleMessage gateway');
let room_name = await this.chatService.getCurrentRoom(socket.username); let room_name = await this.chatService.getCurrentRoom(socket.username);
socket.to(room_name).emit('message', socket.username, message); console.log("-- room_name :", room_name);
//socket.to(room_name).emit('message', socket.username, message);
socket.emit('message', socket.username, message);
this.chatService.addMessageToCurrentRoom(socket.username, message); this.chatService.addMessageToCurrentRoom(socket.username, message);
} }
} }

View File

@@ -3336,6 +3336,7 @@ var app = (function () {
let msgs = writable([]); let msgs = writable([]);
let layout = writable("close"); let layout = writable("close");
let room_name = writable("");
let user; let user;
let socket$1; let socket$1;
function set_user(new_user) { user = new_user; } function set_user(new_user) { user = new_user; }
@@ -3884,19 +3885,20 @@ var app = (function () {
console.log(data.message); console.log(data.message);
socket$1.emit('join', room_name); socket$1.emit('join', room_name);
} }
async function change_room(room_name) { async function change_room(name) {
console.log("in change_room"); console.log("in change_room");
let name = { let r_name = {
room_name: room_name, room_name: name,
}; };
const response = await fetch('/api/v2/chat/change', { const response = await fetch('/api/v2/chat/change', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(name), body: JSON.stringify(r_name),
}); });
let data = await response.json(); let data = await response.json();
console.log(data.message); console.log(data.message);
await get_room_messages(); await get_room_messages();
room_name.set(name);
layout.set("room"); layout.set("room");
} }
async function get_all_rooms() { async function get_all_rooms() {
@@ -4640,7 +4642,7 @@ var app = (function () {
function get_each_context$5(ctx, list, i) { function get_each_context$5(ctx, list, i) {
const child_ctx = ctx.slice(); const child_ctx = ctx.slice();
child_ctx[3] = list[i]; child_ctx[4] = list[i];
return child_ctx; return child_ctx;
} }
@@ -4677,11 +4679,14 @@ var app = (function () {
const block = { const block = {
c: function create() { c: function create() {
t = text("<room_name>"); t = text(/*$room_name*/ ctx[2]);
}, },
m: function mount(target, anchor) { m: function mount(target, anchor) {
insert_dev(target, t, anchor); insert_dev(target, t, anchor);
}, },
p: function update(ctx, dirty) {
if (dirty & /*$room_name*/ 4) set_data_dev(t, /*$room_name*/ ctx[2]);
},
d: function destroy(detaching) { d: function destroy(detaching) {
if (detaching) detach_dev(t); if (detaching) detach_dev(t);
} }
@@ -4728,7 +4733,7 @@ var app = (function () {
// (57:4) <Msg name={msg.name}> // (57:4) <Msg name={msg.name}>
function create_default_slot_1$8(ctx) { function create_default_slot_1$8(ctx) {
let html_tag; let html_tag;
let raw_value = /*msg*/ ctx[3].message + ""; let raw_value = /*msg*/ ctx[4].message + "";
let html_anchor; let html_anchor;
const block = { const block = {
@@ -4742,7 +4747,7 @@ var app = (function () {
insert_dev(target, html_anchor, anchor); insert_dev(target, html_anchor, anchor);
}, },
p: function update(ctx, dirty) { p: function update(ctx, dirty) {
if (dirty & /*$msgs*/ 4 && raw_value !== (raw_value = /*msg*/ ctx[3].message + "")) html_tag.p(raw_value); if (dirty & /*$msgs*/ 8 && raw_value !== (raw_value = /*msg*/ ctx[4].message + "")) html_tag.p(raw_value);
}, },
d: function destroy(detaching) { d: function destroy(detaching) {
if (detaching) detach_dev(html_anchor); if (detaching) detach_dev(html_anchor);
@@ -4768,7 +4773,7 @@ var app = (function () {
msg_1 = new Element_msg({ msg_1 = new Element_msg({
props: { props: {
name: /*msg*/ ctx[3].name, name: /*msg*/ ctx[4].name,
$$slots: { default: [create_default_slot_1$8] }, $$slots: { default: [create_default_slot_1$8] },
$$scope: { ctx } $$scope: { ctx }
}, },
@@ -4785,9 +4790,9 @@ var app = (function () {
}, },
p: function update(ctx, dirty) { p: function update(ctx, dirty) {
const msg_1_changes = {}; const msg_1_changes = {};
if (dirty & /*$msgs*/ 4) msg_1_changes.name = /*msg*/ ctx[3].name; if (dirty & /*$msgs*/ 8) msg_1_changes.name = /*msg*/ ctx[4].name;
if (dirty & /*$$scope, $msgs*/ 1028) { if (dirty & /*$$scope, $msgs*/ 2056) {
msg_1_changes.$$scope = { dirty, ctx }; msg_1_changes.$$scope = { dirty, ctx };
} }
@@ -4895,7 +4900,7 @@ var app = (function () {
$$inline: true $$inline: true
}); });
let each_value = /*$msgs*/ ctx[2]; let each_value = /*$msgs*/ ctx[3];
validate_each_argument(each_value); validate_each_argument(each_value);
let each_blocks = []; let each_blocks = [];
@@ -4910,7 +4915,7 @@ var app = (function () {
button3 = new Element_button({ button3 = new Element_button({
props: { props: {
my_class: "send", my_class: "send",
on_click: /*send_msg*/ ctx[4], on_click: /*send_msg*/ ctx[5],
$$slots: { default: [create_default_slot$a] }, $$slots: { default: [create_default_slot$a] },
$$scope: { ctx } $$scope: { ctx }
}, },
@@ -4939,17 +4944,17 @@ var app = (function () {
t4 = space(); t4 = space();
create_component(button3.$$.fragment); create_component(button3.$$.fragment);
attr_dev(div0, "class", "msg_thread svelte-1quyp80"); attr_dev(div0, "class", "msg_thread svelte-1quyp80");
add_location(div0, file$n, 54, 2, 928); add_location(div0, file$n, 54, 2, 934);
attr_dev(div1, "class", "panel panel_msg svelte-1quyp80"); attr_dev(div1, "class", "panel panel_msg svelte-1quyp80");
add_location(div1, file$n, 53, 1, 896); add_location(div1, file$n, 53, 1, 902);
attr_dev(div2, "class", "text_area svelte-1quyp80"); attr_dev(div2, "class", "text_area svelte-1quyp80");
attr_dev(div2, "contenteditable", "true"); attr_dev(div2, "contenteditable", "true");
if (/*msg*/ ctx[3] === void 0) add_render_callback(() => /*div2_input_handler*/ ctx[6].call(div2)); if (/*msg*/ ctx[4] === void 0) add_render_callback(() => /*div2_input_handler*/ ctx[7].call(div2));
add_location(div2, file$n, 63, 2, 1102); add_location(div2, file$n, 63, 2, 1108);
attr_dev(div3, "class", "panel_write svelte-1quyp80"); attr_dev(div3, "class", "panel_write svelte-1quyp80");
add_location(div3, file$n, 62, 1, 1074); add_location(div3, file$n, 62, 1, 1080);
attr_dev(div4, "class", "grid_box svelte-1quyp80"); attr_dev(div4, "class", "grid_box svelte-1quyp80");
add_location(div4, file$n, 35, 0, 544); add_location(div4, file$n, 35, 0, 555);
}, },
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");
@@ -4973,19 +4978,19 @@ var app = (function () {
append_dev(div4, div3); append_dev(div4, div3);
append_dev(div3, div2); append_dev(div3, div2);
if (/*msg*/ ctx[3] !== void 0) { if (/*msg*/ ctx[4] !== void 0) {
div2.innerHTML = /*msg*/ ctx[3]; div2.innerHTML = /*msg*/ ctx[4];
} }
/*div2_binding*/ ctx[7](div2); /*div2_binding*/ ctx[8](div2);
append_dev(div4, t4); append_dev(div4, t4);
mount_component(button3, div4, null); mount_component(button3, div4, null);
current = true; current = true;
if (!mounted) { if (!mounted) {
dispose = [ dispose = [
listen_dev(div2, "input", /*div2_input_handler*/ ctx[6]), listen_dev(div2, "input", /*div2_input_handler*/ ctx[7]),
listen_dev(div2, "keypress", /*enter_send_msg*/ ctx[5], false, false, false) listen_dev(div2, "keypress", /*enter_send_msg*/ ctx[6], false, false, false)
]; ];
mounted = true; mounted = true;
@@ -4996,28 +5001,28 @@ var app = (function () {
if (dirty & /*back*/ 1) button0_changes.new_layout = /*back*/ ctx[0]; if (dirty & /*back*/ 1) button0_changes.new_layout = /*back*/ ctx[0];
if (dirty & /*back*/ 1) button0_changes.my_title = "go back " + /*back*/ ctx[0]; if (dirty & /*back*/ 1) button0_changes.my_title = "go back " + /*back*/ ctx[0];
if (dirty & /*$$scope*/ 1024) { if (dirty & /*$$scope*/ 2048) {
button0_changes.$$scope = { dirty, ctx }; button0_changes.$$scope = { dirty, ctx };
} }
button0.$set(button0_changes); button0.$set(button0_changes);
const button1_changes = {}; const button1_changes = {};
if (dirty & /*$$scope*/ 1024) { if (dirty & /*$$scope, $room_name*/ 2052) {
button1_changes.$$scope = { dirty, ctx }; button1_changes.$$scope = { dirty, ctx };
} }
button1.$set(button1_changes); button1.$set(button1_changes);
const button2_changes = {}; const button2_changes = {};
if (dirty & /*$$scope*/ 1024) { if (dirty & /*$$scope*/ 2048) {
button2_changes.$$scope = { dirty, ctx }; button2_changes.$$scope = { dirty, ctx };
} }
button2.$set(button2_changes); button2.$set(button2_changes);
if (dirty & /*$msgs*/ 4) { if (dirty & /*$msgs*/ 8) {
each_value = /*$msgs*/ ctx[2]; each_value = /*$msgs*/ ctx[3];
validate_each_argument(each_value); validate_each_argument(each_value);
let i; let i;
@@ -5044,13 +5049,13 @@ var app = (function () {
check_outros(); check_outros();
} }
if (dirty & /*msg*/ 8 && /*msg*/ ctx[3] !== div2.innerHTML) { if (dirty & /*msg*/ 16 && /*msg*/ ctx[4] !== div2.innerHTML) {
div2.innerHTML = /*msg*/ ctx[3]; div2.innerHTML = /*msg*/ ctx[4];
} }
const button3_changes = {}; const button3_changes = {};
if (dirty & /*$$scope*/ 1024) { if (dirty & /*$$scope*/ 2048) {
button3_changes.$$scope = { dirty, ctx }; button3_changes.$$scope = { dirty, ctx };
} }
@@ -5088,7 +5093,7 @@ var app = (function () {
destroy_component(button1); destroy_component(button1);
destroy_component(button2); destroy_component(button2);
destroy_each(each_blocks, detaching); destroy_each(each_blocks, detaching);
/*div2_binding*/ ctx[7](null); /*div2_binding*/ ctx[8](null);
destroy_component(button3); destroy_component(button3);
mounted = false; mounted = false;
run_all(dispose); run_all(dispose);
@@ -5107,9 +5112,12 @@ var app = (function () {
} }
function instance$q($$self, $$props, $$invalidate) { function instance$q($$self, $$props, $$invalidate) {
let $room_name;
let $msgs; let $msgs;
validate_store(room_name, 'room_name');
component_subscribe($$self, room_name, $$value => $$invalidate(2, $room_name = $$value));
validate_store(msgs, 'msgs'); validate_store(msgs, 'msgs');
component_subscribe($$self, msgs, $$value => $$invalidate(2, $msgs = $$value)); component_subscribe($$self, msgs, $$value => $$invalidate(3, $msgs = $$value));
let { $$slots: slots = {}, $$scope } = $$props; let { $$slots: slots = {}, $$scope } = $$props;
validate_slots('Layout_room', slots, []); validate_slots('Layout_room', slots, []);
let { back = "" } = $$props; let { back = "" } = $$props;
@@ -5117,7 +5125,7 @@ var app = (function () {
let text_area; let text_area;
function send_msg() { function send_msg() {
$$invalidate(3, msg = msg.trim()); $$invalidate(4, msg = msg.trim());
if (msg.length > 0) { if (msg.length > 0) {
socket$1.emit('message', msg); socket$1.emit('message', msg);
@@ -5125,7 +5133,7 @@ var app = (function () {
console.log(msgs); console.log(msgs);
} }
$$invalidate(3, msg = ""); $$invalidate(4, msg = "");
text_area.focus(); text_area.focus();
} }
@@ -5144,7 +5152,7 @@ var app = (function () {
function div2_input_handler() { function div2_input_handler() {
msg = this.innerHTML; msg = this.innerHTML;
$$invalidate(3, msg); $$invalidate(4, msg);
} }
function div2_binding($$value) { function div2_binding($$value) {
@@ -5163,6 +5171,7 @@ var app = (function () {
socket: socket$1, socket: socket$1,
msgs, msgs,
add_msg, add_msg,
room_name,
Button: Element_button, Button: Element_button,
Msg: Element_msg, Msg: Element_msg,
back, back,
@@ -5170,12 +5179,13 @@ var app = (function () {
text_area, text_area,
send_msg, send_msg,
enter_send_msg, enter_send_msg,
$room_name,
$msgs $msgs
}); });
$$self.$inject_state = $$props => { $$self.$inject_state = $$props => {
if ('back' in $$props) $$invalidate(0, back = $$props.back); if ('back' in $$props) $$invalidate(0, back = $$props.back);
if ('msg' in $$props) $$invalidate(3, msg = $$props.msg); if ('msg' in $$props) $$invalidate(4, msg = $$props.msg);
if ('text_area' in $$props) $$invalidate(1, text_area = $$props.text_area); if ('text_area' in $$props) $$invalidate(1, text_area = $$props.text_area);
}; };
@@ -5186,6 +5196,7 @@ var app = (function () {
return [ return [
back, back,
text_area, text_area,
$room_name,
$msgs, $msgs,
msg, msg,
send_msg, send_msg,

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,6 @@
<script> <script>
import { layout, socket, msgs, add_msg } from './Store_chat'; import { layout, socket, msgs, add_msg, room_name } from './Store_chat';
import Button from './Element_button.svelte'; import Button from './Element_button.svelte';
import Msg from './Element_msg.svelte'; import Msg from './Element_msg.svelte';
@@ -42,7 +42,7 @@
<!-- room_name --> <!-- room_name -->
<Button new_layout="room_set" my_class="room_name transparent"> <Button new_layout="room_set" my_class="room_name transparent">
&lt;room_name&gt; {$room_name}
</Button> </Button>
<!-- close --> <!-- close -->

View File

@@ -1,4 +1,4 @@
import { msgs, user, layout, socket } from './Store_chat'; import { msgs, user, layout, socket, room_name } from './Store_chat';
export async function get_room_messages() export async function get_room_messages()
{ {
@@ -63,23 +63,24 @@ export async function join_room(room_name)
socket.emit('join', room_name); socket.emit('join', room_name);
} }
export async function change_room(room_name) export async function change_room(name)
{ {
console.log("in change_room"); console.log("in change_room");
let name = { let r_name = {
room_name: room_name, room_name: name,
} }
const response = await fetch('/api/v2/chat/change', { const response = await fetch('/api/v2/chat/change', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(name), body: JSON.stringify(r_name),
}); });
let data = await response.json(); let data = await response.json();
console.log(data.message); console.log(data.message);
await get_room_messages(); await get_room_messages();
room_name.set(name);
layout.set("room"); layout.set("room");
} }

View File

@@ -2,6 +2,7 @@ import { writable } from 'svelte/store';
export let msgs = writable([]); export let msgs = writable([]);
export let layout = writable("close"); export let layout = writable("close");
export let room_name = writable("");
export let user; export let user;
export let socket; export let socket;