This commit is contained in:
NigeParis 2026-01-02 14:14:13 +01:00 committed by Maix0
parent 4f3aab9b7b
commit 949e5a259a

View file

@ -1,5 +1,5 @@
import type { ClientProfil } from './chat_types'; import type { ClientProfil } from './chat_types';
import { clientChat, color } from './app'; import { clientChat } from './app';
import { FastifyInstance } from 'fastify'; import { FastifyInstance } from 'fastify';
/** /**
@ -9,21 +9,18 @@ import { FastifyInstance } from 'fastify';
* @param profil * @param profil
*/ */
export function sendBlocked(fastify: FastifyInstance, blockedMessage: string, profil: ClientProfil) { export async function sendBlocked(fastify: FastifyInstance, blockedMessage: string, profil: ClientProfil) {
fastify.io.fetchSockets().then((sockets) => { const sockets = await fastify.io.fetchSockets();
let targetSocket; let targetSocket;
for (const socket of sockets) { for (const socket of sockets) {
const clientInfo: string = clientChat.get(socket.id)?.user || ''; const clientInfo: string = clientChat.get(socket.id)?.user || '';
if (clientInfo === profil.user) { if (clientInfo === profil.user) {
console.log(color.yellow, 'DEBUG LOG: User found online to block:', profil.user); targetSocket = socket ?? null;
targetSocket = socket || '';
break; break;
} }
} }
profil.text = blockedMessage ?? ''; profil.text = blockedMessage ?? '';
// console.log(color.red, 'DEBUG LOG:',profil.Sendertext);
if (targetSocket) { if (targetSocket) {
targetSocket.emit('blockUser', profil); targetSocket.emit('blockUser', profil);
} }
});
} }