From 71c5914e0483b7640966e6a8b5cb461a93ccbe4a Mon Sep 17 00:00:00 2001 From: NigeParis Date: Mon, 8 Dec 2025 16:26:39 +0100 Subject: [PATCH] profil now displays info on players not connected --- src/chat/src/app.ts | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/src/chat/src/app.ts b/src/chat/src/app.ts index a02fac9..033e17c 100644 --- a/src/chat/src/app.ts +++ b/src/chat/src/app.ts @@ -176,10 +176,10 @@ async function onReady(fastify: FastifyInstance) { }); } - function formatTimestamp(ms: number) { - const d = new Date(ms); - return d.toLocaleString('fr-FR', { timeZone: 'Europe/Paris' }); - } + // function formatTimestamp(ms: number) { + // const d = new Date(ms); + // return d.toLocaleString('fr-FR', { timeZone: 'Europe/Paris' }); + // } function getUserByName(users: User[], name: string) { return users.find(u => u.name === name) || null; @@ -189,28 +189,20 @@ async function onReady(fastify: FastifyInstance) { // this function returns html the profil pop up in CHAT of a user 'nickname unique' TODO .... async function getProfil(user: string): Promise { let profilHtmlPopup = '404: Error: Profil not found'; - const sockets = await fastify.io.fetchSockets(); const users: User[] = fastify.db.getAllUsers() ?? []; + const allUsers: User | null = getUserByName(users, user); + console.log(color.yellow, `'userFound is:'${allUsers?.name}`); + if (user === allUsers?.name) { + console.log(color.yellow, `'login Name: '${allUsers.login}' user: '${user}'`); + profilHtmlPopup = `
+ Profil of ${allUsers.name}
+ Login Name: '${allUsers?.login ?? 'Guest'}' +
+ +
About: No description
+ `; + } - // const senderSocket = sockets.find(socket => socket.id === user); - for (const socket of sockets) { - const clientInfo = clientChat?.get(socket.id); - const allUsers: User | null = getUserByName(users, user); - if (clientInfo?.user === allUsers?.name) { - const lastSeen = formatTimestamp(clientInfo?.lastSeen ?? 0); - console.log(color.yellow, `'Clientinfo.user: '${lastSeen}' user: '${user}'`); - profilHtmlPopup = `
- Profil of ${clientInfo?.user}
- Login Name: '${allUsers?.login ?? 'Guest'}' -
- -
Joined: xx/xx/xx
-
Last connection: ${lastSeen}
-
About: No description
- `; - break; - } - }; return profilHtmlPopup; };