Cleaned un the type obj - now consistant through out

This commit is contained in:
NigeParis 2025-12-17 10:20:07 +01:00
parent f5366bf9e1
commit e543116b5d
2 changed files with 32 additions and 8 deletions

View file

@ -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);

View file

@ -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',
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);