From afd79e334c7c855f09aeb0d24943b131789a7e44 Mon Sep 17 00:00:00 2001 From: NigeParis Date: Fri, 2 Jan 2026 15:11:34 +0100 Subject: [PATCH] First Major Clean Up Done --- frontend/src/pages/chat/chat.ts | 50 ++++--------------- .../actionBtnPopUpBlock.ts | 2 +- .../{ => chatHelperFunctions}/addMessage.ts | 3 -- .../{ => chatHelperFunctions}/blockUser.ts | 4 +- .../{ => chatHelperFunctions}/broadcastMsg.ts | 2 +- .../clearChatWindow.ts | 3 +- .../{ => chatHelperFunctions}/getProfil.ts | 1 - .../{ => chatHelperFunctions}/isLoggedIn.ts | 0 .../{ => chatHelperFunctions}/listBuddies.ts | 4 -- .../openProfilePopup.ts | 2 +- .../windowStateHidden.ts | 2 +- frontend/src/pages/chat/types_front.ts | 7 +++ src/chat/src/app.ts | 18 +++---- .../broadcast.ts | 4 +- .../checkNamePair.ts | 2 +- .../{ => chatBackHelperFunctions}/color.ts | 1 - .../connectedUser.ts | 2 +- .../filter_Blocked_user.ts | 7 +-- .../getUserById.ts | 0 .../getUserByName.ts | 0 .../isBlocked.ts | 0 .../isUser_BlockedBy_me.ts | 6 --- .../list_SocketListener.ts | 7 +-- .../makeProfil.ts | 2 +- .../sendBlocked.ts | 4 +- .../sendInvite.ts | 17 +------ .../sendPrivMessage.ts | 9 +--- .../sendProfil.ts | 3 +- .../whoBlockedMe.ts | 2 +- 29 files changed, 46 insertions(+), 118 deletions(-) rename frontend/src/pages/chat/{ => chatHelperFunctions}/actionBtnPopUpBlock.ts (87%) rename frontend/src/pages/chat/{ => chatHelperFunctions}/addMessage.ts (78%) rename frontend/src/pages/chat/{ => chatHelperFunctions}/blockUser.ts (73%) rename frontend/src/pages/chat/{ => chatHelperFunctions}/broadcastMsg.ts (94%) rename frontend/src/pages/chat/{ => chatHelperFunctions}/clearChatWindow.ts (77%) rename frontend/src/pages/chat/{ => chatHelperFunctions}/getProfil.ts (91%) rename frontend/src/pages/chat/{ => chatHelperFunctions}/isLoggedIn.ts (100%) rename frontend/src/pages/chat/{ => chatHelperFunctions}/listBuddies.ts (91%) rename frontend/src/pages/chat/{ => chatHelperFunctions}/openProfilePopup.ts (95%) rename frontend/src/pages/chat/{ => chatHelperFunctions}/windowStateHidden.ts (93%) rename src/chat/src/{ => chatBackHelperFunctions}/broadcast.ts (91%) rename src/chat/src/{ => chatBackHelperFunctions}/checkNamePair.ts (87%) rename src/chat/src/{ => chatBackHelperFunctions}/color.ts (82%) rename src/chat/src/{ => chatBackHelperFunctions}/connectedUser.ts (97%) rename src/chat/src/{ => chatBackHelperFunctions}/filter_Blocked_user.ts (71%) rename src/chat/src/{ => chatBackHelperFunctions}/getUserById.ts (100%) rename src/chat/src/{ => chatBackHelperFunctions}/getUserByName.ts (100%) rename src/chat/src/{ => chatBackHelperFunctions}/isBlocked.ts (100%) rename src/chat/src/{ => chatBackHelperFunctions}/isUser_BlockedBy_me.ts (71%) rename src/chat/src/{ => chatBackHelperFunctions}/list_SocketListener.ts (64%) rename src/chat/src/{ => chatBackHelperFunctions}/makeProfil.ts (96%) rename src/chat/src/{ => chatBackHelperFunctions}/sendBlocked.ts (88%) rename src/chat/src/{ => chatBackHelperFunctions}/sendInvite.ts (74%) rename src/chat/src/{ => chatBackHelperFunctions}/sendPrivMessage.ts (85%) rename src/chat/src/{ => chatBackHelperFunctions}/sendProfil.ts (79%) rename src/chat/src/{ => chatBackHelperFunctions}/whoBlockedMe.ts (86%) diff --git a/frontend/src/pages/chat/chat.ts b/frontend/src/pages/chat/chat.ts index 8bc8993..2dd224c 100644 --- a/frontend/src/pages/chat/chat.ts +++ b/frontend/src/pages/chat/chat.ts @@ -2,18 +2,18 @@ import './chat.css'; import { addRoute, setTitle, type RouteHandlerParams, type RouteHandlerReturn } from "@app/routing"; import { showError } from "@app/toast"; import authHtml from './chat.html?raw'; -import client from '@app/api' import { getUser, updateUser } from "@app/auth"; import io, { Socket } from 'socket.io-client'; -import { listBuddies } from './listBuddies'; -import { getProfil } from './getProfil'; -import { addMessage } from './addMessage'; -import { broadcastMsg } from './broadcastMsg'; -import { isLoggedIn } from './isLoggedIn'; +import { listBuddies } from './chatHelperFunctions/listBuddies'; +import { getProfil } from './chatHelperFunctions/getProfil'; +import { addMessage } from './chatHelperFunctions/addMessage'; +import { broadcastMsg } from './chatHelperFunctions/broadcastMsg'; +import { isLoggedIn } from './chatHelperFunctions/isLoggedIn'; import type { ClientMessage, ClientProfil } from './types_front'; -import { openProfilePopup } from './openProfilePopup'; -import { actionBtnPopUpBlock } from './actionBtnPopUpBlock'; -import { windowStateHidden } from './windowStateHidden'; +import { openProfilePopup } from './chatHelperFunctions/openProfilePopup'; +import { actionBtnPopUpBlock } from './chatHelperFunctions/actionBtnPopUpBlock'; +import { windowStateHidden } from './chatHelperFunctions/windowStateHidden'; +import type { blockedUnBlocked, obj } from './types_front'; export const color = { red: 'color: red;', @@ -24,28 +24,6 @@ export const color = { }; -export type blockedUnBlocked = -{ - userState: string, - userTarget: string, - by: string, -}; - -export type obj = -{ - command: string, - destination: string, - type: string, - user: string, - frontendUserName: string, - frontendUser: string, - token: string, - text: string, - timestamp: number, - SenderWindowID: string, - Sendertext: string, -}; - const MAX_SYSTEM_MESSAGES = 10; let inviteMsgFlag: boolean = false; @@ -513,10 +491,7 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn SenderID: userID, }; - //socket.emit('MsgObjectServer', message); - // addMessage(message.command); socket.emit('privMessage', JSON.stringify(message)); - // addMessage(JSON.stringify(message)); break; } // Clear the input in all cases @@ -530,7 +505,6 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn if (chatWindow) { chatWindow.innerHTML = ''; } - //clearChatWindow(socket); //DEV testing broadcastGames }); // Dev Game message button @@ -550,12 +524,6 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn sendButton?.click(); } }); - - // Whoami button to display user name addMessage(msgCommand[0]); - - // bwhoami?.addEventListener('click', async () => { - // whoami(socket); - // }); } } diff --git a/frontend/src/pages/chat/actionBtnPopUpBlock.ts b/frontend/src/pages/chat/chatHelperFunctions/actionBtnPopUpBlock.ts similarity index 87% rename from frontend/src/pages/chat/actionBtnPopUpBlock.ts rename to frontend/src/pages/chat/chatHelperFunctions/actionBtnPopUpBlock.ts index 1c12b9d..52f057b 100644 --- a/frontend/src/pages/chat/actionBtnPopUpBlock.ts +++ b/frontend/src/pages/chat/chatHelperFunctions/actionBtnPopUpBlock.ts @@ -1,5 +1,5 @@ import { Socket } from 'socket.io-client'; -import type { ClientProfil } from './types_front'; +import type { ClientProfil } from '../types_front'; import { blockUser } from './blockUser'; export function actionBtnPopUpBlock(block: ClientProfil, senderSocket: Socket) { diff --git a/frontend/src/pages/chat/addMessage.ts b/frontend/src/pages/chat/chatHelperFunctions/addMessage.ts similarity index 78% rename from frontend/src/pages/chat/addMessage.ts rename to frontend/src/pages/chat/chatHelperFunctions/addMessage.ts index 6ced2f2..4f06ae1 100644 --- a/frontend/src/pages/chat/addMessage.ts +++ b/frontend/src/pages/chat/chatHelperFunctions/addMessage.ts @@ -1,5 +1,3 @@ -import { color } from './chat'; - /** * function adds a message to the frontend chatWindow * @param text @@ -13,6 +11,5 @@ export function addMessage(text: string) { messageElement.textContent = text; chatWindow.appendChild(messageElement); chatWindow.scrollTop = chatWindow.scrollHeight; - console.log(`%c DEBUG LOG: Added new message:%c ${text}`, color.red, color.reset); return ; }; \ No newline at end of file diff --git a/frontend/src/pages/chat/blockUser.ts b/frontend/src/pages/chat/chatHelperFunctions/blockUser.ts similarity index 73% rename from frontend/src/pages/chat/blockUser.ts rename to frontend/src/pages/chat/chatHelperFunctions/blockUser.ts index 5f5b966..3d18c2d 100644 --- a/frontend/src/pages/chat/blockUser.ts +++ b/frontend/src/pages/chat/chatHelperFunctions/blockUser.ts @@ -1,11 +1,9 @@ import { Socket } from 'socket.io-client'; -import type { ClientProfil } from './types_front'; +import type { ClientProfil } from '../types_front'; import { getUser } from "@app/auth"; - export function blockUser(profil: ClientProfil, senderSocket: Socket) { profil.SenderName = getUser()?.name ?? ''; if (profil.SenderName === profil.user) return; - // addMessage(`${profil.Sendertext}: ${profil.user}⛔`) senderSocket.emit('blockUser', JSON.stringify(profil)); }; \ No newline at end of file diff --git a/frontend/src/pages/chat/broadcastMsg.ts b/frontend/src/pages/chat/chatHelperFunctions/broadcastMsg.ts similarity index 94% rename from frontend/src/pages/chat/broadcastMsg.ts rename to frontend/src/pages/chat/chatHelperFunctions/broadcastMsg.ts index 586243b..c6f800f 100644 --- a/frontend/src/pages/chat/broadcastMsg.ts +++ b/frontend/src/pages/chat/chatHelperFunctions/broadcastMsg.ts @@ -1,7 +1,7 @@ import { addMessage } from "./addMessage"; import { Socket } from 'socket.io-client'; import { getUser } from "@app/auth"; -import type { ClientMessage } from "./types_front"; +import type { ClientMessage } from "../types_front"; /** * function sends socket.emit to the backend to active and broadcast a message to all sockets * echos the message with addMessage to the sender diff --git a/frontend/src/pages/chat/clearChatWindow.ts b/frontend/src/pages/chat/chatHelperFunctions/clearChatWindow.ts similarity index 77% rename from frontend/src/pages/chat/clearChatWindow.ts rename to frontend/src/pages/chat/chatHelperFunctions/clearChatWindow.ts index 696a007..84694a0 100644 --- a/frontend/src/pages/chat/clearChatWindow.ts +++ b/frontend/src/pages/chat/chatHelperFunctions/clearChatWindow.ts @@ -1,4 +1,4 @@ -import io, { Socket } from 'socket.io-client'; +import { Socket } from 'socket.io-client'; /** * function clears all messages in the chat window @@ -9,5 +9,4 @@ export function clearChatWindow(senderSocket: Socket) { const chatWindow = document.getElementById("t-chatbox") as HTMLDivElement; if (!chatWindow) return; chatWindow.innerHTML = ""; - // senderSocket.emit('nextGame'); } \ No newline at end of file diff --git a/frontend/src/pages/chat/getProfil.ts b/frontend/src/pages/chat/chatHelperFunctions/getProfil.ts similarity index 91% rename from frontend/src/pages/chat/getProfil.ts rename to frontend/src/pages/chat/chatHelperFunctions/getProfil.ts index 1ad7edf..dc7465b 100644 --- a/frontend/src/pages/chat/getProfil.ts +++ b/frontend/src/pages/chat/chatHelperFunctions/getProfil.ts @@ -19,6 +19,5 @@ export function getProfil(socket: Socket, user: string) { timestamp: Date.now(), SenderWindowID: socket.id, }; - // addMessage(JSON.stringify(profil)); socket.emit('profilMessage', JSON.stringify(profil)); } diff --git a/frontend/src/pages/chat/isLoggedIn.ts b/frontend/src/pages/chat/chatHelperFunctions/isLoggedIn.ts similarity index 100% rename from frontend/src/pages/chat/isLoggedIn.ts rename to frontend/src/pages/chat/chatHelperFunctions/isLoggedIn.ts diff --git a/frontend/src/pages/chat/listBuddies.ts b/frontend/src/pages/chat/chatHelperFunctions/listBuddies.ts similarity index 91% rename from frontend/src/pages/chat/listBuddies.ts rename to frontend/src/pages/chat/chatHelperFunctions/listBuddies.ts index bb56a94..6d16f7a 100644 --- a/frontend/src/pages/chat/listBuddies.ts +++ b/frontend/src/pages/chat/chatHelperFunctions/listBuddies.ts @@ -27,20 +27,16 @@ export async function listBuddies(socket: Socket, buddies: HTMLDivElement, listB const user = getUser()?.name ?? ""; buddies.appendChild(buddiesElement); buddies.scrollTop = buddies.scrollHeight; - console.log(`Added buddies: ${bud}`); buddiesElement.style.cursor = "pointer"; buddiesElement.addEventListener("click", () => { navigator.clipboard.writeText(bud); if (bud !== user && user !== "") { sendtextbox.value = `@${bud}: `; - console.log("Copied to clipboard:", bud); sendtextbox.focus(); } }); - buddiesElement.addEventListener("dblclick", () => { - console.log("Open profile:", bud); getProfil(socket, bud); sendtextbox.value = ""; }); diff --git a/frontend/src/pages/chat/openProfilePopup.ts b/frontend/src/pages/chat/chatHelperFunctions/openProfilePopup.ts similarity index 95% rename from frontend/src/pages/chat/openProfilePopup.ts rename to frontend/src/pages/chat/chatHelperFunctions/openProfilePopup.ts index ffd876e..864b1d5 100644 --- a/frontend/src/pages/chat/openProfilePopup.ts +++ b/frontend/src/pages/chat/chatHelperFunctions/openProfilePopup.ts @@ -1,4 +1,4 @@ -import type { ClientProfil } from './types_front'; +import type { ClientProfil } from '../types_front'; export async function openProfilePopup(profil: ClientProfil) { const modalname = document.getElementById("modal-name") ?? null; diff --git a/frontend/src/pages/chat/windowStateHidden.ts b/frontend/src/pages/chat/chatHelperFunctions/windowStateHidden.ts similarity index 93% rename from frontend/src/pages/chat/windowStateHidden.ts rename to frontend/src/pages/chat/chatHelperFunctions/windowStateHidden.ts index 21c26fb..a38ae54 100644 --- a/frontend/src/pages/chat/windowStateHidden.ts +++ b/frontend/src/pages/chat/chatHelperFunctions/windowStateHidden.ts @@ -1,4 +1,4 @@ -import { __socket } from './chat'; +import { __socket } from '../chat'; import { updateUser } from "@app/auth"; export async function windowStateHidden() { diff --git a/frontend/src/pages/chat/types_front.ts b/frontend/src/pages/chat/types_front.ts index 9e74632..85cbbeb 100644 --- a/frontend/src/pages/chat/types_front.ts +++ b/frontend/src/pages/chat/types_front.ts @@ -34,6 +34,13 @@ export type ClientProfil = { }; +export type blockedUnBlocked = +{ + userState: string, + userTarget: string, + by: string, +}; + export type obj = { command: string, diff --git a/src/chat/src/app.ts b/src/chat/src/app.ts index 9bf681c..8f81b82 100644 --- a/src/chat/src/app.ts +++ b/src/chat/src/app.ts @@ -8,18 +8,18 @@ import * as utils from '@shared/utils'; import { Server, Socket } from 'socket.io'; import type { User } from '@shared/database/mixin/user'; import type { BlockedData } from '@shared/database/mixin/blocked'; -import { broadcast } from './broadcast'; +import { broadcast } from './chatBackHelperFunctions/broadcast'; import type { ClientProfil, ClientMessage, obj } from './chat_types'; -import { sendPrivMessage } from './sendPrivMessage'; -import { sendBlocked } from './sendBlocked'; -import { sendInvite } from './sendInvite'; -import { getUserByName } from './getUserByName'; -import { makeProfil } from './makeProfil'; -import { isBlocked } from './isBlocked'; -import { sendProfil } from './sendProfil'; +import { sendPrivMessage } from './chatBackHelperFunctions/sendPrivMessage'; +import { sendBlocked } from './chatBackHelperFunctions/sendBlocked'; +import { sendInvite } from './chatBackHelperFunctions/sendInvite'; +import { getUserByName } from './chatBackHelperFunctions/getUserByName'; +import { makeProfil } from './chatBackHelperFunctions/makeProfil'; +import { isBlocked } from './chatBackHelperFunctions/isBlocked'; +import { sendProfil } from './chatBackHelperFunctions/sendProfil'; import { setGameLink } from './setGameLink'; import { nextGame_SocketListener } from './nextGame_SocketListener'; -import { list_SocketListener } from './list_SocketListener'; +import { list_SocketListener } from './chatBackHelperFunctions/list_SocketListener'; // colors for console.log export const color = { diff --git a/src/chat/src/broadcast.ts b/src/chat/src/chatBackHelperFunctions/broadcast.ts similarity index 91% rename from src/chat/src/broadcast.ts rename to src/chat/src/chatBackHelperFunctions/broadcast.ts index 7b02b96..63e862b 100644 --- a/src/chat/src/broadcast.ts +++ b/src/chat/src/chatBackHelperFunctions/broadcast.ts @@ -1,5 +1,5 @@ -import type { ClientMessage, BlockRelation } from './chat_types'; -import { clientChat } from './app'; +import type { ClientMessage, BlockRelation } from '../chat_types'; +import { clientChat } from '../app'; import { FastifyInstance } from 'fastify'; import { getUserByName } from './getUserByName'; import type { User } from '@shared/database/mixin/user'; diff --git a/src/chat/src/checkNamePair.ts b/src/chat/src/chatBackHelperFunctions/checkNamePair.ts similarity index 87% rename from src/chat/src/checkNamePair.ts rename to src/chat/src/chatBackHelperFunctions/checkNamePair.ts index 5110f60..e4a1afd 100644 --- a/src/chat/src/checkNamePair.ts +++ b/src/chat/src/chatBackHelperFunctions/checkNamePair.ts @@ -1,4 +1,4 @@ -import type { BlockRelation } from './chat_types'; +import type { BlockRelation } from '../chat_types'; export function checkNamePair(list: BlockRelation[], name1: string, name2: string): (boolean) { const matches: BlockRelation[] = []; diff --git a/src/chat/src/color.ts b/src/chat/src/chatBackHelperFunctions/color.ts similarity index 82% rename from src/chat/src/color.ts rename to src/chat/src/chatBackHelperFunctions/color.ts index cb87c2c..c3b2e31 100644 --- a/src/chat/src/color.ts +++ b/src/chat/src/chatBackHelperFunctions/color.ts @@ -1,4 +1,3 @@ -// colors for console.log export const color = { red: '\x1b[31m', green: '\x1b[32m', diff --git a/src/chat/src/connectedUser.ts b/src/chat/src/chatBackHelperFunctions/connectedUser.ts similarity index 97% rename from src/chat/src/connectedUser.ts rename to src/chat/src/chatBackHelperFunctions/connectedUser.ts index a030a7e..a9c16af 100644 --- a/src/chat/src/connectedUser.ts +++ b/src/chat/src/chatBackHelperFunctions/connectedUser.ts @@ -1,4 +1,4 @@ -import { clientChat } from './app'; +import { clientChat } from '../app'; import { Server, Socket } from 'socket.io'; /** diff --git a/src/chat/src/filter_Blocked_user.ts b/src/chat/src/chatBackHelperFunctions/filter_Blocked_user.ts similarity index 71% rename from src/chat/src/filter_Blocked_user.ts rename to src/chat/src/chatBackHelperFunctions/filter_Blocked_user.ts index 3cdded5..d404b87 100644 --- a/src/chat/src/filter_Blocked_user.ts +++ b/src/chat/src/chatBackHelperFunctions/filter_Blocked_user.ts @@ -1,4 +1,4 @@ -import type { ClientMessage } from './chat_types'; +import type { ClientMessage } from '../chat_types'; import { FastifyInstance } from 'fastify'; import type { User } from '@shared/database/mixin/user'; import { getUserById } from './getUserById'; @@ -17,11 +17,6 @@ export function filter_Blocked_user(fastify: FastifyInstance, data: ClientMessag const UserToBlock: string = id; const UserAskingToBlock: User | null = getUserById(users, `${data.SenderUserID}`); if (!UserAskingToBlock) { - // console.log('SOMETHING NULL', data); - // console.log('UsetToBlock', UserToBlock?.id); - // console.log('UsetToBlock', UserToBlock?.name); - // console.log('UsetAskingToBlock', UserAskingToBlock?.id); - // console.log('UsetAskingToBlock', UserAskingToBlock?.name); return false; } if (isUser_BlockedBy_me(fastify, UserAskingToBlock!.id, UserToBlock)) { diff --git a/src/chat/src/getUserById.ts b/src/chat/src/chatBackHelperFunctions/getUserById.ts similarity index 100% rename from src/chat/src/getUserById.ts rename to src/chat/src/chatBackHelperFunctions/getUserById.ts diff --git a/src/chat/src/getUserByName.ts b/src/chat/src/chatBackHelperFunctions/getUserByName.ts similarity index 100% rename from src/chat/src/getUserByName.ts rename to src/chat/src/chatBackHelperFunctions/getUserByName.ts diff --git a/src/chat/src/isBlocked.ts b/src/chat/src/chatBackHelperFunctions/isBlocked.ts similarity index 100% rename from src/chat/src/isBlocked.ts rename to src/chat/src/chatBackHelperFunctions/isBlocked.ts diff --git a/src/chat/src/isUser_BlockedBy_me.ts b/src/chat/src/chatBackHelperFunctions/isUser_BlockedBy_me.ts similarity index 71% rename from src/chat/src/isUser_BlockedBy_me.ts rename to src/chat/src/chatBackHelperFunctions/isUser_BlockedBy_me.ts index 797e027..638f3fa 100644 --- a/src/chat/src/isUser_BlockedBy_me.ts +++ b/src/chat/src/chatBackHelperFunctions/isUser_BlockedBy_me.ts @@ -3,7 +3,6 @@ import type { User } from '@shared/database/mixin/user'; import type { BlockedData } from '@shared/database/mixin/blocked'; import { isBlocked } from './isBlocked'; import { getUserById } from './getUserById'; -import { color } from './color'; /** * checks the Db for the two matching Ids @@ -19,20 +18,15 @@ export function isUser_BlockedBy_me(fastify: FastifyInstance, blockedBy_Id : str const UserToBlock: User | null = getUserById(users, `${isBlocked_Id}`); const UserAskingToBlock: User | null = getUserById(users, `${blockedBy_Id}`); if (!UserToBlock) { - console.log(color.blue, `'User: ${UserAskingToBlock?.id} has not blocked' ${isBlocked_Id}`); return ''; } if (!UserAskingToBlock) { - console.log(color.blue, `'User: ${UserToBlock?.id} has not blocked by' ${blockedBy_Id}`); return ''; } const usersBlocked: BlockedData[] = fastify.db.getAllBlockedUsers() ?? []; const userAreBlocked: boolean = isBlocked(UserAskingToBlock, UserToBlock, usersBlocked); if (userAreBlocked) { - console.log(color.yellow, `'User :${UserAskingToBlock.name}) Hhas UN blocked ${UserToBlock.name}`); return UserAskingToBlock.name; } - console.log(color.blue, `'User :${UserAskingToBlock.name}) has BBBblocked ${UserToBlock.name}`); - return ''; }; diff --git a/src/chat/src/list_SocketListener.ts b/src/chat/src/chatBackHelperFunctions/list_SocketListener.ts similarity index 64% rename from src/chat/src/list_SocketListener.ts rename to src/chat/src/chatBackHelperFunctions/list_SocketListener.ts index a2584ed..aa02315 100644 --- a/src/chat/src/list_SocketListener.ts +++ b/src/chat/src/chatBackHelperFunctions/list_SocketListener.ts @@ -1,8 +1,7 @@ import type { FastifyInstance } from 'fastify'; import { Socket } from 'socket.io'; -import { clientChat } from './app'; +import { clientChat } from '../app'; import { connectedUser } from './connectedUser'; -// import { color } from './app'; export function list_SocketListener(fastify: FastifyInstance, socket: Socket) { @@ -10,11 +9,8 @@ export function list_SocketListener(fastify: FastifyInstance, socket: Socket) { const userFromFrontend = object || null; const client = clientChat.get(socket.id) || null; - // console.log(color.red, 'DEBUG LOG: list activated', userFromFrontend, color.reset, socket.id) if (userFromFrontend.oldUser !== userFromFrontend.user) { - // console.log(color.red, 'DEBUG LOG: list activated', userFromFrontend.oldUser, color.reset); if (client?.user === null) { - console.log('ERROR: clientName is NULL'); return; }; if (client) { @@ -23,5 +19,4 @@ export function list_SocketListener(fastify: FastifyInstance, socket: Socket) { } connectedUser(fastify.io, socket.id); }); - } \ No newline at end of file diff --git a/src/chat/src/makeProfil.ts b/src/chat/src/chatBackHelperFunctions/makeProfil.ts similarity index 96% rename from src/chat/src/makeProfil.ts rename to src/chat/src/chatBackHelperFunctions/makeProfil.ts index 1fee65b..3324135 100644 --- a/src/chat/src/makeProfil.ts +++ b/src/chat/src/chatBackHelperFunctions/makeProfil.ts @@ -1,5 +1,5 @@ import { FastifyInstance } from 'fastify'; -import type { ClientProfil } from './chat_types'; +import type { ClientProfil } from '../chat_types'; import type { User } from '@shared/database/mixin/user'; import { getUserByName } from './getUserByName'; import { Socket } from 'socket.io'; diff --git a/src/chat/src/sendBlocked.ts b/src/chat/src/chatBackHelperFunctions/sendBlocked.ts similarity index 88% rename from src/chat/src/sendBlocked.ts rename to src/chat/src/chatBackHelperFunctions/sendBlocked.ts index 98effb5..de09d68 100644 --- a/src/chat/src/sendBlocked.ts +++ b/src/chat/src/chatBackHelperFunctions/sendBlocked.ts @@ -1,5 +1,5 @@ -import type { ClientProfil } from './chat_types'; -import { clientChat } from './app'; +import type { ClientProfil } from '../chat_types'; +import { clientChat } from '../app'; import { FastifyInstance } from 'fastify'; /** diff --git a/src/chat/src/sendInvite.ts b/src/chat/src/chatBackHelperFunctions/sendInvite.ts similarity index 74% rename from src/chat/src/sendInvite.ts rename to src/chat/src/chatBackHelperFunctions/sendInvite.ts index e65cd46..21e7e39 100644 --- a/src/chat/src/sendInvite.ts +++ b/src/chat/src/chatBackHelperFunctions/sendInvite.ts @@ -1,5 +1,5 @@ -import type { ClientMessage, ClientProfil } from './chat_types'; -import { clientChat, color } from './app'; +import type { ClientMessage, ClientProfil } from '../chat_types'; +import { clientChat } from '../app'; import { FastifyInstance } from 'fastify'; import { sendPrivMessage } from './sendPrivMessage'; @@ -16,15 +16,12 @@ export function sendInvite(fastify: FastifyInstance, innerHtml: string, profil: fastify.io.fetchSockets().then((sockets) => { let targetSocket; for (const socket of sockets) { - console.log(color.yellow, 'DEBUG LOG: sendInvite Function'); const clientInfo: string = clientChat.get(socket.id)?.user || ''; - console.log(color.green, 'AskingName=', profil.SenderName); targetSocket = socket || null; if (!targetSocket) continue; if (clientInfo === profil.user) { profil.innerHtml = innerHtml ?? ''; if (targetSocket.id) { - const data: ClientMessage = { command: `@${clientInfo}`, destination: 'inviteMsg', @@ -41,18 +38,8 @@ export function sendInvite(fastify: FastifyInstance, innerHtml: string, profil: SenderUserID: '', Sendertext: '', innerHtml: innerHtml, - }; - - console.log(color.yellow, 'DEBUG LOG: sendInvite Function -> sendPrivMessage :'); sendPrivMessage(fastify, data, ''); - - - // targetSocket.emit('MsgObjectServer', { message: data }); - - - // targetSocket.emit('inviteGame', profil); - } return; } diff --git a/src/chat/src/sendPrivMessage.ts b/src/chat/src/chatBackHelperFunctions/sendPrivMessage.ts similarity index 85% rename from src/chat/src/sendPrivMessage.ts rename to src/chat/src/chatBackHelperFunctions/sendPrivMessage.ts index 502ad69..b5bc46c 100644 --- a/src/chat/src/sendPrivMessage.ts +++ b/src/chat/src/chatBackHelperFunctions/sendPrivMessage.ts @@ -1,5 +1,5 @@ -import type { ClientMessage } from './chat_types'; -import { clientChat, color } from './app'; +import type { ClientMessage } from '../chat_types'; +import { clientChat } from '../app'; import { FastifyInstance } from 'fastify'; import { getUserByName } from './getUserByName'; import type { User } from '@shared/database/mixin/user'; @@ -20,7 +20,6 @@ function checkNamePair(list: BlockRelation[], name1: string, name2: string): (bo return true;; } } - console.log(color.red, `'RETURN FLAG CheckNamePair ${exists}' item: ${name1} item2: ${name2}`); } return exists; } @@ -55,7 +54,6 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess const list:BlockRelation[] = whoBlockedMe(fastify, UserID); const clientInfo = clientChat.get(socket.id); if (!clientInfo?.user) { - console.log(color.red, `Skipping socket ${socket.id} (no user found)`); continue; } let blockMsgFlag: boolean = false; @@ -67,14 +65,11 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess const user: string = clientChat.get(socket.id)?.user ?? ''; const atUser = `@${user}`; if (atUser !== data.command || atUser === '' || data.text === '') { - console.log(color.red, 'DEBUG: atUser !== data.command'); continue; } blockMsgFlag = checkNamePair(list, UserID, UserByID.id) || false; - if (socket.id === sender) { - console.log(color.blue, 'sKip Sender ', socket.id); continue; } if (!blockMsgFlag) { diff --git a/src/chat/src/sendProfil.ts b/src/chat/src/chatBackHelperFunctions/sendProfil.ts similarity index 79% rename from src/chat/src/sendProfil.ts rename to src/chat/src/chatBackHelperFunctions/sendProfil.ts index b07633c..dc18eda 100644 --- a/src/chat/src/sendProfil.ts +++ b/src/chat/src/chatBackHelperFunctions/sendProfil.ts @@ -1,5 +1,5 @@ import { FastifyInstance } from 'fastify'; -import type { ClientProfil } from './chat_types'; +import type { ClientProfil } from '../chat_types'; /** * function takes a user profil and sends it to the asker by window id @@ -12,7 +12,6 @@ export function sendProfil(fastify: FastifyInstance, profil: ClientProfil, Sende fastify.io.fetchSockets().then((sockets) => { const senderSocket = sockets.find(socket => socket.id === SenderWindowID); if (senderSocket) { - // console.log(color.yellow, 'DEBUG LOG: profil.info:', profil.user); senderSocket.emit('profilMessage', profil); } }); diff --git a/src/chat/src/whoBlockedMe.ts b/src/chat/src/chatBackHelperFunctions/whoBlockedMe.ts similarity index 86% rename from src/chat/src/whoBlockedMe.ts rename to src/chat/src/chatBackHelperFunctions/whoBlockedMe.ts index ea483d5..8755ff4 100644 --- a/src/chat/src/whoBlockedMe.ts +++ b/src/chat/src/chatBackHelperFunctions/whoBlockedMe.ts @@ -1,5 +1,5 @@ import { FastifyInstance } from 'fastify'; -import type { BlockRelation } from './chat_types'; +import type { BlockRelation } from '../chat_types'; export function whoBlockedMe(fastify: FastifyInstance, myID: string): BlockRelation [] { const usersBlocked =