diff --git a/back/volume/src/chat/chat.gateway.ts b/back/volume/src/chat/chat.gateway.ts index 899c2a1..7a34f47 100644 --- a/back/volume/src/chat/chat.gateway.ts +++ b/back/volume/src/chat/chat.gateway.ts @@ -43,6 +43,12 @@ export class ChatGateway implements OnGatewayConnection, OnGatewayDisconnect { async handleConnection (socket: Socket): Promise {} async handleDisconnect (socket: Socket): Promise { + const connect = await this.connectedUserRepository.findOneBy({ + socket: socket.id + }) + if (connect) + await this.connectedUserRepository.delete({ socket: socket.id }) + socket.disconnect() console.log('socket %s has disconnected', socket.id) } diff --git a/front/volume/src/App.svelte b/front/volume/src/App.svelte index 8b86fcf..a6f04a3 100644 --- a/front/volume/src/App.svelte +++ b/front/volume/src/App.svelte @@ -34,36 +34,10 @@ // Single Page Application config let appState: string = APPSTATE.HOME; - - async function updateChat() { - const urlSplit = appState.split("#", 2) - if (appState.includes(APPSTATE.CHANNELS) && urlSplit.length > 1) { - const currentChannelName = appState.split("#", 2)[1]; - fetch(API_URL + "/channels", { - credentials: "include", - mode: "cors", - }).then((res) => { - res.json().then(async (channels) => { - await formatChannelNames(channels); - const channel = channels.find((c: ChannelsType) => c.name === currentChannelName); - selectedChannel = channel; - if (channel) { - chan.selectChat(channel.id); // disabled as it causes a bug where joining a channel happen twice - } else { - alert("Failed loading channel"); - } - }); - }).catch(() => { - alert("Failed loading channel"); - }); - } - } - history.replaceState({ appState: "" }, "", "/"); window.onpopstate = (e: PopStateEvent) => { if (e.state) { appState = e.state.appState; - void updateChat(); // why this? } }; @@ -75,7 +49,6 @@ if (newState === appState) return; appState = newState; history.pushState({ appState }, "", appState); - void updateChat(); } onMount(() => { @@ -169,6 +142,7 @@ } let selectedChannel: ChannelsType; const handleSelectChannel = (channel: ChannelsType) => { + selectedChannel = channel; setAppState(APPSTATE.CHANNELS + "#" + channel.name); }; diff --git a/front/volume/src/components/Channels.svelte b/front/volume/src/components/Channels.svelte index 6943db7..9a3552b 100644 --- a/front/volume/src/components/Channels.svelte +++ b/front/volume/src/components/Channels.svelte @@ -17,7 +17,6 @@ } import { onMount } from "svelte"; import { API_URL, store } from "../Auth"; - import { socket } from "../socket"; import type User from "./Profile.svelte"; export async function formatChannelNames(channel: Array): Promise { @@ -76,25 +75,6 @@ return true; } - const joinChannel = async (channel: ChannelsType) => { - console.log(channels) - socket.connect(); - if (!channel.password) { - socket.emit("joinChannel", { - UserId: $store.ftId, - ChannelId: channel.id, - }); - } else { - await show_popup("Channel is protected, enter password:") - socket.emit("joinChannel", { - UserId: $store.ftId, - ChannelId: channel.id, - pwd: $content, - }); - } - console.log("Try to join channel: ", $store.ftId, channel.id, $content) - }; - const getChannels = async () => { const res = await fetch(API_URL + "/channels", { credentials: "include", @@ -116,20 +96,6 @@ export let onSelectChannel: (channel: ChannelsType) => void; - let channel: ChannelsType; - - export const selectChat = (id: number) => { - console.log("channel: ", id) - getChannels().then(() => { - channel = channels.find((c) => c.id === id); - if (channel) { - joinChannel(channel); - } else { - show_popup("Did not find channel", false) - } - - }) - }; const createChannel = async () => { let name: string; diff --git a/front/volume/src/components/Chat.svelte b/front/volume/src/components/Chat.svelte index 7cd03b3..baff9b8 100644 --- a/front/volume/src/components/Chat.svelte +++ b/front/volume/src/components/Chat.svelte @@ -1,7 +1,7 @@