From 66a99471970eabaf3bd091dba8ce03e6c5ad67d9 Mon Sep 17 00:00:00 2001 From: NigeParis Date: Wed, 7 Jan 2026 15:08:15 +0100 Subject: [PATCH] WIP no guest msg flagger --- frontend/src/pages/chat/chat.html | 1 + frontend/src/pages/chat/chat.ts | 42 ++++++++++++++++--- .../chat/chatHelperFunctions/setGuestInfo.ts | 24 +++++++++++ frontend/src/pages/chat/types_front.ts | 1 + package.json | 4 +- src/chat/src/app.ts | 19 +++++++++ src/chat/src/chat_types.ts | 1 + 7 files changed, 85 insertions(+), 7 deletions(-) create mode 100644 frontend/src/pages/chat/chatHelperFunctions/setGuestInfo.ts diff --git a/frontend/src/pages/chat/chat.html b/frontend/src/pages/chat/chat.html index 954768a..4c90758 100644 --- a/frontend/src/pages/chat/chat.html +++ b/frontend/src/pages/chat/chat.html @@ -18,6 +18,7 @@
🔕
+
💔
diff --git a/frontend/src/pages/chat/chat.ts b/frontend/src/pages/chat/chat.ts index b0f4d3e..1cc274d 100644 --- a/frontend/src/pages/chat/chat.ts +++ b/frontend/src/pages/chat/chat.ts @@ -391,7 +391,9 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn // Send button sendButton?.addEventListener("click", () => { const notify = document.getElementById("notify") ?? null; - const noGuest = document.getElementById("guestMsg") ?? null; + const noGuest = document.getElementById("noGuest") ?? null; + const userId = getUser()?.id; + const userAskingToBlock = getUser()?.name; if (sendtextbox && sendtextbox.value.trim()) { let msgText: string = sendtextbox.value.trim(); const msgCommand = parseCmdMsg(msgText) ?? ""; @@ -403,17 +405,15 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn break; case '@block': if (msgCommand[1] === '') {break;}; - const userAskingToBlock = getUser()?.name; if (!userAskingToBlock) return; - const userID1 = getUser()?.id; - if (!userID1) return; + if (!userId) return; const userToBlock: ClientProfil = { command: msgCommand[0], destination: '', type: 'chat', user: msgCommand[1], loginName: '', - userID: userID1, + userID: userId, text: '', timestamp: Date.now(), SenderWindowID: '', @@ -433,7 +433,39 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn notify.innerText = '🔕'; inviteMsgFlag = false; } + break; + + case '@guest': + if (!userId) return; + if (!userAskingToBlock) return; + if (noGuest === null) {break;}; + if (noGuestFlag === false) { + noGuest.innerText = '❤️​'; + noGuestFlag = true; + } else { + noGuest.innerText = '💔'; + noGuestFlag = false; + } + const userProfile: ClientProfil = { + command: '@noguest', + destination: '', + type: 'chat', + user: '', + loginName: '', + userID: userId, + text: '', + timestamp: Date.now(), + SenderWindowID: '', + SenderName: userAskingToBlock, + SenderID: '', + Sendertext: '', + innerHtml: '', + guestmsg: noGuestFlag, + } + socket.emit('guestmsg', JSON.stringify(userProfile)); + break; + case '@profile': if (msgCommand[1] === '') {break;}; getProfil(socket, msgCommand[1]); diff --git a/frontend/src/pages/chat/chatHelperFunctions/setGuestInfo.ts b/frontend/src/pages/chat/chatHelperFunctions/setGuestInfo.ts new file mode 100644 index 0000000..e675cf8 --- /dev/null +++ b/frontend/src/pages/chat/chatHelperFunctions/setGuestInfo.ts @@ -0,0 +1,24 @@ +import { Socket } from 'socket.io-client'; + +/** + * getProfil of a user + * @param socket + * @param user + * @returns + */ + +export function setGuestInfo(socket: Socket, user: string, guest: boolean) { + if (!socket.connected) return; + const profilInfo = { + command: '@guestInfo', + destination: 'guestInfo', + type: "chat", + user: user, + token: document.cookie ?? "", + text: user, + timestamp: Date.now(), + SenderWindowID: socket.id, + guest: guest, + }; + socket.emit('guestInfo', JSON.stringify(profilInfo)); +} diff --git a/frontend/src/pages/chat/types_front.ts b/frontend/src/pages/chat/types_front.ts index 85cbbeb..e668e4a 100644 --- a/frontend/src/pages/chat/types_front.ts +++ b/frontend/src/pages/chat/types_front.ts @@ -31,6 +31,7 @@ export type ClientProfil = { SenderID: string, Sendertext: string, innerHtml?: string, + guestmsg?: boolean, }; diff --git a/package.json b/package.json index 01ef809..d77eb0d 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,8 @@ "license": "ISC", "packageManager": "pnpm@10", "devDependencies": { - "@redocly/cli": "^2.12.7", + "@redocly/cli": "^2.14.3", "husky": "^9.1.7", - "vite": "^7.3.0" + "vite": "^7.3.1" } } diff --git a/src/chat/src/app.ts b/src/chat/src/app.ts index 98b4399..855fb47 100644 --- a/src/chat/src/app.ts +++ b/src/chat/src/app.ts @@ -79,6 +79,7 @@ declare module 'fastify' { io: Server<{ MsgObjectServer: (data: { message: ClientMessage }) => void; privMessage: (data: string) => void; + guestmsg: (data: string) => void; profilMessage: (data: ClientProfil) => void; inviteGame: (data: ClientProfil) => void; blockUser: (data: ClientProfil) => void; @@ -255,6 +256,24 @@ async function onReady(fastify: FastifyInstance) { } }); + socket.on('guestmsg', (data) => { + const clientName: string = clientChat.get(socket.id)?.user || ''; + const profile: ClientProfil = JSON.parse(data) || ''; + const users: User[] = fastify.db.getAllUsers() ?? []; + const user: User | null = getUserByName(users, clientName); + if (!user) return; + if (clientName !== null) { + + if (profile.guestmsg) {console.log('Data TRUE:', clientName);} else {console.log('Data FALSE'); }; + + + if(fastify.db.getGuestMessage(user?.id)) {console.log('TRUE')}; + + } + }); + + + socket.on('profilMessage', async (data: string) => { const clientName: string = clientChat.get(socket.id)?.user || ''; diff --git a/src/chat/src/chat_types.ts b/src/chat/src/chat_types.ts index e9173db..c8b937e 100644 --- a/src/chat/src/chat_types.ts +++ b/src/chat/src/chat_types.ts @@ -31,6 +31,7 @@ export type ClientProfil = { SenderID: string, Sendertext: string, innerHtml?: string, + guestmsg?: boolean, };