Fixed Priv Message Blockage - now working

This commit is contained in:
NigeParis 2025-12-22 13:37:31 +01:00 committed by Maix0
parent 97d7318cf9
commit 117b535962
3 changed files with 26 additions and 20 deletions

View file

@ -542,6 +542,7 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
}; };
//socket.emit('MsgObjectServer', message); //socket.emit('MsgObjectServer', message);
// addMessage(message.command);
socket.emit('privMessage', JSON.stringify(message)); socket.emit('privMessage', JSON.stringify(message));
// addMessage(JSON.stringify(message)); // addMessage(JSON.stringify(message));
break; break;

View file

@ -58,6 +58,7 @@ export async function broadcast(fastify: FastifyInstance, data: ClientMessage, s
console.log(color.red, 'sKip Sender ', socket.id); console.log(color.red, 'sKip Sender ', socket.id);
continue; continue;
} }
console.log(`BROADCAST blockFlag=${blockMsgFlag} : Target ${clientInfo.user}`);
if (!blockMsgFlag) { if (!blockMsgFlag) {
console.log(color.blue, 'Emit message: ', data.command, 'blockMsgFlag: ', blockMsgFlag); console.log(color.blue, 'Emit message: ', data.command, 'blockMsgFlag: ', blockMsgFlag);
socket.emit('MsgObjectServer', { message: data }); socket.emit('MsgObjectServer', { message: data });

View file

@ -20,6 +20,7 @@ function checkNamePair(list: BlockRelation[], name1: string, name2: string): (bo
return true;; return true;;
} }
} }
console.log(color.red, `'RETURN FLAG CheckNamePair ${exists}' item: ${name1} item2: ${name2}`);
} }
return exists; return exists;
} }
@ -46,39 +47,42 @@ function whoBlockedMe(fastify: FastifyInstance, myID: string): BlockRelation []
export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMessage, sender?: string) { export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMessage, sender?: string) {
const AllusersBlocked: User[] = fastify.db.getAllUsers() ?? [];
const UserID = getUserByName(AllusersBlocked, data.user)?.id ?? '';
const list:BlockRelation[] = whoBlockedMe(fastify, UserID);
const sockets = await fastify.io.fetchSockets(); const sockets = await fastify.io.fetchSockets();
const AllusersBlocked: User[] = fastify.db.getAllUsers() ?? [];
const senderSocket = sockets.find(socket => socket.id === sender); const senderSocket = sockets.find(socket => socket.id === sender);
for (const socket of sockets) { for (const socket of sockets) {
if (socket.id === sender) continue; const UserID = getUserByName(AllusersBlocked, data.user)?.id ?? '';
const list:BlockRelation[] = whoBlockedMe(fastify, UserID);
const clientInfo = clientChat.get(socket.id); const clientInfo = clientChat.get(socket.id);
if (!clientInfo?.user) { if (!clientInfo?.user) {
console.log(color.yellow, `DEBUG LOG: Skipping socket ${socket.id} (no user found)`); console.log(color.red, `Skipping socket ${socket.id} (no user found)`);
continue; continue;
} }
let blockMsgFlag: boolean = false; let blockMsgFlag: boolean = false;
const UserByID = getUserByName(AllusersBlocked, clientInfo.user)?.id ?? ''; const UserByID = getUserByName(AllusersBlocked, clientInfo.user) ?? '';
if (UserByID === '') { if (UserByID === '') return;
blockMsgFlag = checkNamePair(list, data.SenderUserID, UserByID) || false;
}
const user: string = clientChat.get(socket.id)?.user ?? ''; const user: string = clientChat.get(socket.id)?.user ?? '';
const atUser = `@${user}`; const atUser = `@${user}`;
if (atUser !== data.command || atUser === '') { if (atUser !== data.command || atUser === '' || data.text === '') {
console.log(color.yellow, `DEBUG LOG: User: '${atUser}' command NOT FOUND: '${data.command[0]}' `);
continue; continue;
} }
if (data.text !== '') {
if (!blockMsgFlag) { blockMsgFlag = checkNamePair(list, UserID, UserByID.id) || false;
console.log(color.blue, 'Emit message: ', data.command, 'blockMsgFlag: ', blockMsgFlag); console.log(color.green, `USER ID: ${UserID} data.user: ${data.user} blockFlag: ${blockMsgFlag} userName: ${UserByID.name} iD:${UserByID.id}`);
// socket.emit('MsgObjectServer', { message: data });
console.log(color.yellow, `DEBUG LOG: User: '${atUser}' command FOUND: '${data.command}' `); if (socket.id === sender) {
if (senderSocket) { console.log(color.blue, 'sKip Sender ', socket.id);
senderSocket.emit('privMessageCopy', `${data.command}: ${data.text}🔒`); continue;
} }
console.log(color.yellow, `blockFlag=${blockMsgFlag}: Target ${clientInfo.user}`);
if (!blockMsgFlag) {
console.log(color.blue, 'Emit message: ', data.command, 'blockMsgFlag: ', blockMsgFlag);
socket.emit('MsgObjectServer', { message: data });
if (senderSocket) {
senderSocket.emit('privMessageCopy', `${data.command}: ${data.text}🔒`);
} }
} }
console.log(color.green, `DEBUG LOG: 'Priv to:', ${data.command} message: ${data.text}`);
} }
} }