diff --git a/frontend/src/chat/chat.ts b/frontend/src/chat/chat.ts index 5834d06..2e0746d 100644 --- a/frontend/src/chat/chat.ts +++ b/frontend/src/chat/chat.ts @@ -384,15 +384,18 @@ sendButton?.addEventListener("click", () => { let toggle = false; window.addEventListener("focus", async () => { + console.log('--------------------------') + console.log('Window focus called Called'); + console.log('--------------------------') setTimeout(() => { if (window.__state.chatSock) connected(window.__state.chatSock); }, 16); - if (window.location.pathname === "/app/chat") { - if (window.__state.chatSock?.id) { + // if (window.location.pathname === "/app/chat") { + // if (window.__state.chatSock?.id) { await windowStateVisable(); - } + // } toggle = true; - } + // } }); window.addEventListener("blur", () => { @@ -419,13 +422,17 @@ sendtextbox.addEventListener("keydown", (event) => { } }); -chatButton!.addEventListener("click", () => { +chatButton!.addEventListener("click", async () => { if (chatBox.classList.contains("hidden")) { chatBox.classList.toggle("hidden"); overlay.classList.add("opacity-60"); + await windowStateVisable(); + + } else { chatBox.classList.toggle("hidden"); overlay.classList.remove("opacity-60"); + await windowStateHidden(); } }); diff --git a/frontend/src/chat/chatHelperFunctions/addMessage.ts b/frontend/src/chat/chatHelperFunctions/addMessage.ts index adfed81..7158e4a 100644 --- a/frontend/src/chat/chatHelperFunctions/addMessage.ts +++ b/frontend/src/chat/chatHelperFunctions/addMessage.ts @@ -28,14 +28,3 @@ export function addInviteMessage(text: string) { chatWindow.scrollTop = chatWindow.scrollHeight; return ; }; - - - // if (chatWindow && data.message.destination === "inviteMsg") { - // const messageElement = document.createElement("div-private"); - // const chatWindow = document.getElementById( - // "t-chatbox", - // ) as HTMLDivElement; - // messageElement.innerHTML = `🏓${data.message.SenderUserName}: ${data.message.innerHtml}`; - // chatWindow.appendChild(messageElement); - // chatWindow.scrollTop = chatWindow.scrollHeight; - // } \ No newline at end of file diff --git a/frontend/src/chat/chatHelperFunctions/quitChat.ts b/frontend/src/chat/chatHelperFunctions/quitChat.ts index 6ddc978..6fd7e2c 100644 --- a/frontend/src/chat/chatHelperFunctions/quitChat.ts +++ b/frontend/src/chat/chatHelperFunctions/quitChat.ts @@ -1,16 +1,13 @@ -import { Socket } from "socket.io-client"; -import { getSocket } from "../chat"; -import { logout } from "./logout"; -import { connected } from "./connected"; import { showError } from "@app/toast"; -import { setTitle } from "@app/routing"; +import { windowStateVisable } from "./windowStateVisable"; +import { windowStateHidden } from "./windowStateHidden"; /** * function to quit the chat - leaves the ping-Buddies list - * @param socket + * */ -export function quitChat () { +export async function quitChat () { const chatBox = document.getElementById("chatBox")!; const overlay = document.querySelector('#overlay')!; @@ -18,7 +15,10 @@ export function quitChat () { if (chatBox.classList.contains('hidden')) { // chatBox.classList.toggle('hidden'); // overlay.classList.add('opacity-60'); + await windowStateVisable(); + } else { + await windowStateHidden(); chatBox.classList.toggle('hidden'); overlay.classList.remove('opacity-60'); } diff --git a/frontend/src/chat/chatHelperFunctions/windowStateHidden.ts b/frontend/src/chat/chatHelperFunctions/windowStateHidden.ts index 27d45f9..b7e0b03 100644 --- a/frontend/src/chat/chatHelperFunctions/windowStateHidden.ts +++ b/frontend/src/chat/chatHelperFunctions/windowStateHidden.ts @@ -1,6 +1,9 @@ import { updateUser } from "@app/auth"; export async function windowStateHidden() { + console.log('--------------------------') + console.log('WindowState Hidden Called'); + console.log('--------------------------') const socketId = window.__state.chatSock || undefined; // let oldName = localStorage.getItem("oldName") ?? undefined; let oldName: string; diff --git a/frontend/src/chat/chatHelperFunctions/windowStateVisable.ts b/frontend/src/chat/chatHelperFunctions/windowStateVisable.ts index 6ff315b..10a8528 100644 --- a/frontend/src/chat/chatHelperFunctions/windowStateVisable.ts +++ b/frontend/src/chat/chatHelperFunctions/windowStateVisable.ts @@ -9,6 +9,9 @@ import { updateUser } from "@app/auth"; export async function windowStateVisable() { + console.log('--------------------------') + console.log('WindowState Visable Called'); + console.log('--------------------------') const buddies = document.getElementById('div-buddies') as HTMLDivElement; const socketId = window.__state.chatSock || undefined; let oldName = localStorage.getItem("oldName") || undefined; diff --git a/src/chat/src/app.ts b/src/chat/src/app.ts index 1244cb5..b3a6751 100644 --- a/src/chat/src/app.ts +++ b/src/chat/src/app.ts @@ -174,10 +174,6 @@ async function onReady(fastify: FastifyInstance) { socket.on('privMessage', (data) => { const clientName: string = clientChat.get(socket.id)?.user || ''; const prvMessage: ClientMessage = JSON.parse(data) || ''; - console.log("------------------------------------------------") - console.log("PRUV GAME") - console.log(data) - console.log("------------------------------------------------") if (clientName !== null) { const obj: ClientMessage = { command: prvMessage.command, @@ -187,7 +183,7 @@ async function onReady(fastify: FastifyInstance) { text: prvMessage.text, timestamp: Date.now(), SenderWindowID: socket.id, - };`` + }; sendPrivMessage(fastify, obj, obj.SenderWindowID); } }); @@ -221,11 +217,6 @@ async function onReady(fastify: FastifyInstance) { socket.on('inviteGame', async (data: string) => { const clientName: string = clientChat.get(socket.id)?.user || ''; const profilInvite: ClientProfil = JSON.parse(data) || ''; - console.log("------------------------------------------------") - console.log("INVITE GAME") - console.log(data) - console.log("------------------------------------------------") - const linkGame: PongGameId | undefined = await setGameLink(fastify, data); if (!linkGame) return; const link: string = `Click me`; diff --git a/src/chat/src/chatBackHelperFunctions/sendPrivMessage.ts b/src/chat/src/chatBackHelperFunctions/sendPrivMessage.ts index a53d53f..7b1508c 100644 --- a/src/chat/src/chatBackHelperFunctions/sendPrivMessage.ts +++ b/src/chat/src/chatBackHelperFunctions/sendPrivMessage.ts @@ -23,9 +23,7 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess const sockets = await fastify.io.fetchSockets(); const allUsers: User[] = fastify.db.getAllUsers() ?? []; - console.log('sender', sender); const senderSocket = sockets.find(socket => socket.id === sender); - console.log('senderSOcket', senderSocket?.id); for (const socket of sockets) { if (socket.id === sender) continue; @@ -46,20 +44,16 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess } blockMsgFlag = checkNamePair(list, UserID, receiverUser.id) || false; - console.log("userID", UserID); - console.log("receiverUserID", receiverUser.id) if (!blockMsgFlag) { socket.emit('MsgObjectServer', { message: data }); fastify.log.info({ senderID: `${UserID}`, msgPriv: data.text, target: `${receiverUser.id}` }); if (senderSocket) { if (!data.innerHtml) { - console.log('privMsg text'); senderSocket.emit('privMessageCopy', `${data.command}: ${data.text}🔒`); - } else { - console.log('privMsg texthtml'); + } + else { senderSocket.emit('privMessageCopy', `${data.command}: ${data.innerHtml}🔒`); } - } } }