turned off console.logs to see clearly on the WIP block user
This commit is contained in:
parent
cd621e6c1a
commit
cd0f2bd3d2
2 changed files with 47 additions and 40 deletions
|
|
@ -169,7 +169,7 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
broadcast(fastify, obj, obj.SenderWindowID);
|
broadcast(fastify, obj, obj.SenderWindowID);
|
||||||
|
|
||||||
const users: User[] = fastify.db.getAllUsers() ?? [];
|
const users: User[] = fastify.db.getAllUsers() ?? [];
|
||||||
console.log('DEBUG: senderWindow :', getUserById(users, obj.SenderUserID)?.name);
|
// console.log('DEBUG: senderWindow :', getUserById(users, obj.SenderUserID)?.name);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -228,7 +228,7 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
const clientName = clientInfo?.user;
|
const clientName = clientInfo?.user;
|
||||||
|
|
||||||
if (!clientName) return;
|
if (!clientName) return;
|
||||||
console.log(color.green, `Client logging out: ${clientName} (${socket.id})`);
|
// console.log(color.green, `Client logging out: ${clientName} (${socket.id})`);
|
||||||
const obj: ClientMessage = {
|
const obj: ClientMessage = {
|
||||||
command: '',
|
command: '',
|
||||||
destination: 'system-info',
|
destination: 'system-info',
|
||||||
|
|
@ -254,11 +254,11 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
|
|
||||||
socket.on('disconnecting', (reason) => {
|
socket.on('disconnecting', (reason) => {
|
||||||
const clientName = clientChat.get(socket.id)?.user || null;
|
const clientName = clientChat.get(socket.id)?.user || null;
|
||||||
console.log(
|
// console.log(
|
||||||
color.green,
|
// color.green,
|
||||||
`Client disconnecting: ${clientName} (${socket.id}) reason:`,
|
// `Client disconnecting: ${clientName} (${socket.id}) reason:`,
|
||||||
reason,
|
// reason,
|
||||||
);
|
// );
|
||||||
if (reason === 'transport error') return;
|
if (reason === 'transport error') return;
|
||||||
|
|
||||||
if (clientName !== null) {
|
if (clientName !== null) {
|
||||||
|
|
@ -285,12 +285,12 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
|
|
||||||
socket.on('client_left', (data) => {
|
socket.on('client_left', (data) => {
|
||||||
const clientName = clientChat.get(socket.id)?.user || null;
|
const clientName = clientChat.get(socket.id)?.user || null;
|
||||||
const leftChat = data || null;
|
//const leftChat = data || null;
|
||||||
console.log(
|
// console.log(
|
||||||
color.green,
|
// color.green,
|
||||||
`Left the Chat User: ${clientName} id Socket: ${socket.id} reason:`,
|
// `Left the Chat User: ${clientName} id Socket: ${socket.id} reason:`,
|
||||||
leftChat.why,
|
// leftChat.why,
|
||||||
);
|
// );
|
||||||
|
|
||||||
if (clientName !== null) {
|
if (clientName !== null) {
|
||||||
const obj: ClientMessage = {
|
const obj: ClientMessage = {
|
||||||
|
|
@ -320,11 +320,11 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
socket.on('privMessage', (data) => {
|
socket.on('privMessage', (data) => {
|
||||||
const clientName: string = clientChat.get(socket.id)?.user || '';
|
const clientName: string = clientChat.get(socket.id)?.user || '';
|
||||||
const prvMessage: ClientMessage = JSON.parse(data) || '';
|
const prvMessage: ClientMessage = JSON.parse(data) || '';
|
||||||
console.log(
|
// console.log(
|
||||||
color.blue,
|
// color.blue,
|
||||||
`DEBUG LOG: ClientName: '${clientName}' id Socket: '${socket.id}' target Name:`,
|
// `DEBUG LOG: ClientName: '${clientName}' id Socket: '${socket.id}' target Name:`,
|
||||||
prvMessage.command,
|
// prvMessage.command,
|
||||||
);
|
// );
|
||||||
|
|
||||||
if (clientName !== null) {
|
if (clientName !== null) {
|
||||||
const obj: ClientMessage = {
|
const obj: ClientMessage = {
|
||||||
|
|
@ -352,14 +352,14 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
socket.on('profilMessage', async (data: string) => {
|
socket.on('profilMessage', async (data: string) => {
|
||||||
const clientName: string = clientChat.get(socket.id)?.user || '';
|
const clientName: string = clientChat.get(socket.id)?.user || '';
|
||||||
const profilMessage: ClientMessage = JSON.parse(data) || '';
|
const profilMessage: ClientMessage = JSON.parse(data) || '';
|
||||||
const users: User[] = fastify.db.getAllUsers() ?? [];
|
// const users: User[] = fastify.db.getAllUsers() ?? [];
|
||||||
// console.log(color.yellow, 'DEBUG LOG: ALL USERS EVER CONNECTED:', users);
|
// console.log(color.yellow, 'DEBUG LOG: ALL USERS EVER CONNECTED:', users);
|
||||||
// console.log(color.blue, `DEBUG LOG: ClientName: '${clientName}' id Socket: '${socket.id}' target profil:`, profilMessage.user);
|
// console.log(color.blue, `DEBUG LOG: ClientName: '${clientName}' id Socket: '${socket.id}' target profil:`, profilMessage.user);
|
||||||
const profile: ClientProfil = await makeProfil(fastify, profilMessage.user, socket);
|
const profile: ClientProfil = await makeProfil(fastify, profilMessage.user, socket);
|
||||||
if (clientName !== null) {
|
if (clientName !== null) {
|
||||||
const testuser: User | null = getUserByName(users, profilMessage.user);
|
// const testuser: User | null = getUserByName(users, profilMessage.user);
|
||||||
console.log(color.yellow, 'user:', testuser?.name ?? 'Guest');
|
// console.log(color.yellow, 'user:', testuser?.name ?? 'Guest');
|
||||||
console.log(color.blue, 'DEBUG - profil message MESSAGE OUT :', profile.SenderWindowID);
|
// console.log(color.blue, 'DEBUG - profil message MESSAGE OUT :', profile.SenderWindowID);
|
||||||
sendProfil(fastify, profile, profile.SenderWindowID);
|
sendProfil(fastify, profile, profile.SenderWindowID);
|
||||||
// clientChat.delete(obj.user);
|
// clientChat.delete(obj.user);
|
||||||
}
|
}
|
||||||
|
|
@ -458,14 +458,14 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
|
|
||||||
|
|
||||||
if (userAreBlocked) {
|
if (userAreBlocked) {
|
||||||
console.log(color.green, 'Both users are blocked as requested');
|
// console.log(color.green, 'Both users are blocked as requested');
|
||||||
// return true; // or any other action you need to take
|
// return true; // or any other action you need to take
|
||||||
|
|
||||||
|
|
||||||
console.log(color.red, 'ALL BLOCKED USERS:', usersBlocked);
|
// console.log(color.red, 'ALL BLOCKED USERS:', usersBlocked);
|
||||||
fastify.db.removeBlockedUserFor(UserAskingToBlock!.id, UserToBlock!.id);
|
fastify.db.removeBlockedUserFor(UserAskingToBlock!.id, UserToBlock!.id);
|
||||||
const usersBlocked2 = fastify.db.getAllBlockedUsers();
|
// const usersBlocked2 = fastify.db.getAllBlockedUsers();
|
||||||
console.log(color.green, 'remove A BLOCKED USER:', usersBlocked2);
|
// console.log(color.green, 'remove A BLOCKED USER:', usersBlocked2);
|
||||||
if (clientName !== null) {
|
if (clientName !== null) {
|
||||||
const blockedMessage = 'I have un-blocked you';
|
const blockedMessage = 'I have un-blocked you';
|
||||||
if (clientName !== null) {
|
if (clientName !== null) {
|
||||||
|
|
@ -500,11 +500,11 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
console.log(color.red, 'The users are not blocked in this way');
|
// console.log(color.red, 'The users are not blocked in this way');
|
||||||
console.log(color.red, 'ALL BLOCKED USERS:', usersBlocked);
|
// console.log(color.red, 'ALL BLOCKED USERS:', usersBlocked);
|
||||||
fastify.db.addBlockedUserFor(UserAskingToBlock!.id, UserToBlock!.id);
|
fastify.db.addBlockedUserFor(UserAskingToBlock!.id, UserToBlock!.id);
|
||||||
const usersBlocked2 = fastify.db.getAllBlockedUsers();
|
// const usersBlocked2 = fastify.db.getAllBlockedUsers();
|
||||||
console.log(color.green, 'ALL BLOCKED USERS:', usersBlocked2);
|
// console.log(color.green, 'ALL BLOCKED USERS:', usersBlocked2);
|
||||||
if (clientName !== null) {
|
if (clientName !== null) {
|
||||||
const blockedMessage = 'I have blocked you';
|
const blockedMessage = 'I have blocked you';
|
||||||
profilBlock.Sendertext = 'You have blocked ';
|
profilBlock.Sendertext = 'You have blocked ';
|
||||||
|
|
@ -563,10 +563,10 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
// client.user = clientName;
|
// client.user = clientName;
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
console.log(
|
// console.log(
|
||||||
color.green,
|
// color.green,
|
||||||
`Client entered the Chat: ${clientName} (${socket.id})`,
|
// `Client entered the Chat: ${clientName} (${socket.id})`,
|
||||||
);
|
// );
|
||||||
if (clientName !== null) {
|
if (clientName !== null) {
|
||||||
const obj: ClientMessage = {
|
const obj: ClientMessage = {
|
||||||
command: '',
|
command: '',
|
||||||
|
|
|
||||||
|
|
@ -37,15 +37,22 @@ export function broadcast(fastify: FastifyInstance, data: ClientMessage, sender?
|
||||||
//console.log(color.yellow, 'me:', getUserByName(AllusersBlocked, data.user)?.id)
|
//console.log(color.yellow, 'me:', getUserByName(AllusersBlocked, data.user)?.id)
|
||||||
const UserByName = getUserByName(AllusersBlocked, data.user)?.id ?? "";
|
const UserByName = getUserByName(AllusersBlocked, data.user)?.id ?? "";
|
||||||
const list:BlockRelation[] = whoBlockedMe(fastify, UserByName);
|
const list:BlockRelation[] = whoBlockedMe(fastify, UserByName);
|
||||||
const blockers = list.map(r => r.blocker);
|
|
||||||
const blocked = list.map(r => r.blocked);
|
|
||||||
console.log('All blockers:', blockers);
|
|
||||||
console.log('All blocked:', blocked);
|
const blockers = list.map(read => read.blocker);
|
||||||
|
const blocked = list.map(read => read.blocked);
|
||||||
|
|
||||||
|
console.log('All blockers:', blockers);
|
||||||
|
console.log('All blocked:', blocked);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//console.log(color.yellow, 'list:', list)
|
//console.log(color.yellow, 'list:', list)
|
||||||
fastify.io.fetchSockets().then((sockets) => {
|
fastify.io.fetchSockets().then((sockets) => {
|
||||||
for (const socket of sockets) {
|
for (const socket of sockets) {
|
||||||
// Skip sender's own socket
|
// Skip sender's own socket
|
||||||
//if (socket.id === sender) continue;
|
if (socket.id === sender) continue;
|
||||||
// Get client name from map
|
// Get client name from map
|
||||||
const clientInfo = clientChat.get(socket.id);
|
const clientInfo = clientChat.get(socket.id);
|
||||||
if (!clientInfo?.user) {
|
if (!clientInfo?.user) {
|
||||||
|
|
@ -69,7 +76,7 @@ console.log('All blocked:', blocked);
|
||||||
// } else {
|
// } else {
|
||||||
// console.log('FALSE → sender IS blocked');
|
// console.log('FALSE → sender IS blocked');
|
||||||
// }
|
// }
|
||||||
if (list.filter(entry => entry.blocker === UserByID)) continue;
|
//if (list.filter(entry => entry.blocker === UserByID)) continue;
|
||||||
socket.emit('MsgObjectServer', { message: data });
|
socket.emit('MsgObjectServer', { message: data });
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue