diff --git a/frontend/src/pages/chat/chat.ts b/frontend/src/pages/chat/chat.ts index 985216a..2790626 100644 --- a/frontend/src/pages/chat/chat.ts +++ b/frontend/src/pages/chat/chat.ts @@ -31,6 +31,21 @@ export type blockedUnBlocked = 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, +}; + // get the name of the machine used to connect const machineHostName = window.location.hostname; console.log('connect to login at %chttps://' + machineHostName + ':8888/app/login',color.yellow); @@ -242,7 +257,7 @@ async function openMessagePopup(message: string) { const modalmessage = document.getElementById("modal-message") ?? null; if(!message) return - const obj:any = JSON.parse(message); + const obj:string = JSON.parse(message); if (modalmessage) { const messageElement = document.createElement("div"); messageElement.innerHTML = ` @@ -341,7 +356,7 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn profil.SenderID = getUser()?.id ?? ""; profil.SenderName = getUser()?.name ?? ""; openProfilePopup(profil); - console.log(`DEBUG LOG: userId:${profil.userID}: senderID ${profil.SenderID}' senderID:${getUser()?.id}`); + console.log(`DEBUG LOG: userId:${profil.userID}: senderID${profil.SenderID}' senderID:${getUser()?.id}`); console.log(`DEBUG LOG: user:${profil.user}: sender:${profil.SenderName}' senderID:${getUser()?.name}`); socket.emit('check_Block_button', profil); actionBtnPopUpClear(profil, socket); diff --git a/src/chat/src/app.ts b/src/chat/src/app.ts index 7f9e5c5..bf27c55 100644 --- a/src/chat/src/app.ts +++ b/src/chat/src/app.ts @@ -189,7 +189,7 @@ async function onReady(fastify: FastifyInstance) { socket.on('message', (message: string) => { // console.info(color.blue, 'DEBUG LOG: Socket connected!', color.reset, socket.id); // console.log( color.blue, 'DEBUG LOG: Received message from client', color.reset, message); - const obj: ClientMessage = JSON.parse(message) as ClientMessage; + const obj: obj = JSON.parse(message) as ClientMessage; clientChat.set(socket.id, { user: obj.user, lastSeen: Date.now() }); // console.log(color.green, 'DEBUG LOG: Message from client', color.reset, `Sender: login name: ${obj.user} - windowID ${obj.SenderWindowID} - text message: ${obj.text}`); socket.emit('welcome', { msg: 'Welcome to the chat! : ' }); @@ -247,15 +247,18 @@ async function onReady(fastify: FastifyInstance) { if (!clientName) return; console.log(color.green, `Client logging out: ${clientName} (${socket.id})`); - const obj = { + const obj: obj = { command: '', destination: 'system-info', type: 'chat' as const, user: clientName, token: '', text: 'LEFT the chat', - timestamp: Date.now(), - SenderWindowID: socket.id, + frontendUserName: '', + frontendUser: '', + timestamp: Date.now(), + SenderWindowID: socket.id, + Sendertext: '', }; broadcast(fastify, obj, socket.id); // Optional: remove from map @@ -274,15 +277,18 @@ async function onReady(fastify: FastifyInstance) { if (reason === 'transport error') return; if (clientName !== null) { - const obj = { + const obj: obj = { command: '', destination: 'system-info', type: 'chat', user: clientName, token: '', text: 'LEFT the chat', + frontendUserName: '', + frontendUser: '', timestamp: Date.now(), SenderWindowID: socket.id, + Sendertext: '', }; broadcast(fastify, obj, obj.SenderWindowID); @@ -299,15 +305,18 @@ async function onReady(fastify: FastifyInstance) { ); if (clientName !== null) { - const obj = { + const obj: obj = { command: '', destination: 'system-info', type: 'chat', user: clientName, token: '', text: 'LEFT the chat but the window is still open', + frontendUserName: '', + frontendUser: '', timestamp: Date.now(), SenderWindowID: socket.id, + Sendertext: '', }; // console.log(color.blue, 'DEBUG LOG: BROADCASTS OUT :', obj.SenderWindowID);