rebased Master amd eslint - activated logs Raph for merge with master because eslint makes problems with graphana not activated
This commit is contained in:
parent
9f0e626e29
commit
2299294f0e
6 changed files with 135 additions and 212 deletions
14
Docker.mk
14
Docker.mk
|
|
@ -6,7 +6,7 @@
|
||||||
# By: nrobinso <nrobinso@student.42.fr> +#+ +:+ +#+ #
|
# By: nrobinso <nrobinso@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2025/06/11 18:10:26 by maiboyer #+# #+# #
|
# Created: 2025/06/11 18:10:26 by maiboyer #+# #+# #
|
||||||
# Updated: 2025/12/17 11:34:56 by nrobinso ### ########.fr #
|
# Updated: 2025/12/19 09:19:02 by nrobinso ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -14,12 +14,12 @@
|
||||||
|
|
||||||
# TODO: REMOVE THIS BEFORE LAUNCH
|
# TODO: REMOVE THIS BEFORE LAUNCH
|
||||||
# this allows the us to only start the non-monitoring sercices
|
# this allows the us to only start the non-monitoring sercices
|
||||||
DOCKER_SERVICE= \
|
# DOCKER_SERVICE=
|
||||||
auth \
|
# auth \
|
||||||
chat \
|
# chat \
|
||||||
frontend \
|
# frontend \
|
||||||
nginx \
|
# nginx \
|
||||||
user \
|
# user \
|
||||||
|
|
||||||
all: build
|
all: build
|
||||||
docker compose up -d $(DOCKER_SERVICE)
|
docker compose up -d $(DOCKER_SERVICE)
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ import { sendProfil } from './sendProfil';
|
||||||
import { setGameLink } from './setGameLink';
|
import { setGameLink } from './setGameLink';
|
||||||
import { nextGame_SocketListener } from './nextGame_SocketListener';
|
import { nextGame_SocketListener } from './nextGame_SocketListener';
|
||||||
import { list_SocketListener } from './list_SocketListener';
|
import { list_SocketListener } from './list_SocketListener';
|
||||||
import { filter_Blocked_user } from './filter_Blocked_user'
|
|
||||||
|
|
||||||
// colors for console.log
|
// colors for console.log
|
||||||
export const color = {
|
export const color = {
|
||||||
|
|
@ -111,8 +110,6 @@ declare module 'fastify' {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* function get the object user in an array of users[] by name
|
* function get the object user in an array of users[] by name
|
||||||
* @param users
|
* @param users
|
||||||
|
|
@ -128,25 +125,25 @@ function isUser_BlockedBy_me(fastify: FastifyInstance, blockedBy_Id : string, is
|
||||||
if (!users) return '';
|
if (!users) return '';
|
||||||
const UserToBlock: User | null = getUserById(users, `${isBlocked_Id}`);
|
const UserToBlock: User | null = getUserById(users, `${isBlocked_Id}`);
|
||||||
const UserAskingToBlock: User | null = getUserById(users, `${blockedBy_Id}`);
|
const UserAskingToBlock: User | null = getUserById(users, `${blockedBy_Id}`);
|
||||||
if (!UserToBlock) {console.log(color.blue, `'User: ${UserAskingToBlock?.id} has not blocked' ${isBlocked_Id}`); return ""};
|
if (!UserToBlock) {
|
||||||
if (!UserAskingToBlock) {console.log(color.blue, `'User: ${UserToBlock?.id} has not blocked by' ${blockedBy_Id}`); return ""};
|
console.log(color.blue, `'User: ${UserAskingToBlock?.id} has not blocked' ${isBlocked_Id}`);
|
||||||
|
return '';
|
||||||
|
};
|
||||||
|
if (!UserAskingToBlock) {
|
||||||
|
console.log(color.blue, `'User: ${UserToBlock?.id} has not blocked by' ${blockedBy_Id}`);
|
||||||
|
return '';
|
||||||
|
};
|
||||||
const usersBlocked: BlockedData[] = fastify.db.getAllBlockedUsers() ?? [];
|
const usersBlocked: BlockedData[] = fastify.db.getAllBlockedUsers() ?? [];
|
||||||
const userAreBlocked: boolean = isBlocked(UserAskingToBlock, UserToBlock, usersBlocked);
|
const userAreBlocked: boolean = isBlocked(UserAskingToBlock, UserToBlock, usersBlocked);
|
||||||
if (userAreBlocked) {
|
if (userAreBlocked) {
|
||||||
console.log(color.yellow, `'User :${UserAskingToBlock.name}) Hhas UN blocked ${UserToBlock.name}`)
|
console.log(color.yellow, `'User :${UserAskingToBlock.name}) Hhas UN blocked ${UserToBlock.name}`);
|
||||||
return UserAskingToBlock.name;
|
return UserAskingToBlock.name;
|
||||||
}
|
}
|
||||||
console.log(color.blue, `'User :${UserAskingToBlock.name}) has BBBblocked ${UserToBlock.name}`)
|
console.log(color.blue, `'User :${UserAskingToBlock.name}) has BBBblocked ${UserToBlock.name}`);
|
||||||
|
return '';
|
||||||
return "";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function onReady(fastify: FastifyInstance) {
|
async function onReady(fastify: FastifyInstance) {
|
||||||
|
|
||||||
|
|
||||||
// shows address for connection au server transcendance
|
// shows address for connection au server transcendance
|
||||||
const session = process.env.SESSION_MANAGER ?? '';
|
const session = process.env.SESSION_MANAGER ?? '';
|
||||||
if (session) {
|
if (session) {
|
||||||
|
|
@ -155,9 +152,7 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
console.log(color.yellow, 'Connect at : https://' + machineName + ':8888/app/login');
|
console.log(color.yellow, 'Connect at : https://' + machineName + ':8888/app/login');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fastify.io.on('connection', (socket: Socket) => {
|
fastify.io.on('connection', (socket: Socket) => {
|
||||||
|
|
||||||
socket.on('message', (message: string) => {
|
socket.on('message', (message: string) => {
|
||||||
// console.info(color.blue, 'DEBUG LOG: Socket connected!', color.reset, socket.id);
|
// 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);
|
// console.log( color.blue, 'DEBUG LOG: Received message from client', color.reset, message);
|
||||||
|
|
@ -168,44 +163,25 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
// Send object directly — DO NOT wrap it in a string
|
// Send object directly — DO NOT wrap it in a string
|
||||||
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);
|
||||||
|
// fastify.io.fetchSockets().then((sockets) => {
|
||||||
|
// for (const socket of sockets) {
|
||||||
|
// const clientInfo = clientChat.get(socket.id);
|
||||||
|
// if (!clientInfo?.user) {
|
||||||
// fastify.io.fetchSockets().then((sockets) => {
|
// console.log(color.yellow, `Skipping socket ${socket.id} (no user found)`);
|
||||||
// for (const socket of sockets) {
|
// continue;
|
||||||
// const clientInfo = clientChat.get(socket.id);
|
// }
|
||||||
// if (!clientInfo?.user) {
|
// console.log('DEBUG: UserIDWindow :', getUserByName(users, clientInfo.user)?.id);
|
||||||
// console.log(color.yellow, `Skipping socket ${socket.id} (no user found)`);
|
// const IDUser = getUserByName(users, clientInfo.user)?.id;
|
||||||
// continue;
|
// console.log(filter_Blocked_user(fastify, obj, IDUser?? ""));
|
||||||
// }
|
// }
|
||||||
// console.log('DEBUG: UserIDWindow :', getUserByName(users, clientInfo.user)?.id);
|
// });
|
||||||
// const IDUser = getUserByName(users, clientInfo.user)?.id;
|
|
||||||
|
|
||||||
// console.log(filter_Blocked_user(fastify, obj, IDUser?? ""));
|
|
||||||
|
|
||||||
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// console.log(color.red, 'DEBUG LOG: connected in the Chat :', connectedUser(fastify.io), color.reset);
|
// console.log(color.red, 'DEBUG LOG: connected in the Chat :', connectedUser(fastify.io), color.reset);
|
||||||
});
|
});
|
||||||
|
|
||||||
nextGame_SocketListener(fastify, socket);
|
nextGame_SocketListener(fastify, socket);
|
||||||
|
|
||||||
list_SocketListener(fastify, socket);
|
list_SocketListener(fastify, socket);
|
||||||
|
|
||||||
|
|
||||||
socket.on('updateClientName', (object) => {
|
socket.on('updateClientName', (object) => {
|
||||||
const userFromFrontend = object || null;
|
const userFromFrontend = object || null;
|
||||||
const client = clientChat.get(socket.id) || null;
|
const client = clientChat.get(socket.id) || null;
|
||||||
|
|
@ -254,11 +230,7 @@ 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, `Client disconnecting: ${clientName} (${socket.id}) reason:`, reason,);
|
||||||
// color.green,
|
|
||||||
// `Client disconnecting: ${clientName} (${socket.id}) reason:`,
|
|
||||||
// reason,
|
|
||||||
// );
|
|
||||||
if (reason === 'transport error') return;
|
if (reason === 'transport error') return;
|
||||||
|
|
||||||
if (clientName !== null) {
|
if (clientName !== null) {
|
||||||
|
|
@ -284,14 +256,9 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('client_left', (data) => {
|
socket.on('client_left', (data) => {
|
||||||
|
void 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(color.green, `Left the Chat User: ${clientName} id Socket: ${socket.id} reason:`, leftChat.why,);
|
||||||
// console.log(
|
|
||||||
// color.green,
|
|
||||||
// `Left the Chat User: ${clientName} id Socket: ${socket.id} reason:`,
|
|
||||||
// leftChat.why,
|
|
||||||
// );
|
|
||||||
|
|
||||||
if (clientName !== null) {
|
if (clientName !== null) {
|
||||||
const obj: ClientMessage = {
|
const obj: ClientMessage = {
|
||||||
command: '',
|
command: '',
|
||||||
|
|
@ -320,12 +287,7 @@ 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, `DEBUG LOG: ClientName: '${clientName}' id Socket: '${socket.id}' target Name:`, prvMessage.command,);
|
||||||
// color.blue,
|
|
||||||
// `DEBUG LOG: ClientName: '${clientName}' id Socket: '${socket.id}' target Name:`,
|
|
||||||
// prvMessage.command,
|
|
||||||
// );
|
|
||||||
|
|
||||||
if (clientName !== null) {
|
if (clientName !== null) {
|
||||||
const obj: ClientMessage = {
|
const obj: ClientMessage = {
|
||||||
command: prvMessage.command,
|
command: prvMessage.command,
|
||||||
|
|
@ -345,7 +307,7 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
};
|
};
|
||||||
// console.log(color.blue, 'DEBUG LOG: PRIV MESSAGE OUT :', obj.SenderWindowID);
|
// console.log(color.blue, 'DEBUG LOG: PRIV MESSAGE OUT :', obj.SenderWindowID);
|
||||||
sendPrivMessage(fastify, obj, obj.SenderWindowID);
|
sendPrivMessage(fastify, obj, obj.SenderWindowID);
|
||||||
// clientChat.delete(obj.user);
|
// clientChat.delete(obj.user);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -361,7 +323,7 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
// 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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -392,30 +354,24 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
|
|
||||||
if (!UserAskingToBlock || !UserToBlock) return;
|
if (!UserAskingToBlock || !UserToBlock) return;
|
||||||
|
|
||||||
if(isUser_BlockedBy_me(fastify, UserAskingToBlock!.id, UserToBlock!.id)) {
|
if (isUser_BlockedBy_me(fastify, UserAskingToBlock!.id, UserToBlock!.id)) {
|
||||||
const message: blockedUnBlocked =
|
const message: blockedUnBlocked = {
|
||||||
{
|
userState: 'block',
|
||||||
userState: "block",
|
userTarget: UserToBlock.name,
|
||||||
userTarget: UserToBlock.name,
|
by: UserAskingToBlock.name,
|
||||||
by: UserAskingToBlock.name,
|
};
|
||||||
|
socket.emit('blockBtn', message);
|
||||||
|
}
|
||||||
};
|
else {
|
||||||
socket.emit('blockBtn', message);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
const message: blockedUnBlocked =
|
|
||||||
{
|
|
||||||
userState: "un-block",
|
|
||||||
userTarget: UserToBlock.name,
|
|
||||||
by: UserAskingToBlock.name,
|
|
||||||
|
|
||||||
};
|
|
||||||
socket.emit('blockBtn', message);
|
|
||||||
|
|
||||||
|
|
||||||
} });
|
|
||||||
|
|
||||||
|
const message: blockedUnBlocked = {
|
||||||
|
userState: 'un-block',
|
||||||
|
userTarget: UserToBlock.name,
|
||||||
|
by: UserAskingToBlock.name,
|
||||||
|
};
|
||||||
|
socket.emit('blockBtn', message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
socket.on('blockUser', async (data: string) => {
|
socket.on('blockUser', async (data: string) => {
|
||||||
const clientName: string = clientChat.get(socket.id)?.user || '';
|
const clientName: string = clientChat.get(socket.id)?.user || '';
|
||||||
|
|
@ -433,35 +389,27 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
const usersBlocked: BlockedData[] = fastify.db.getAllBlockedUsers() ?? [];
|
const usersBlocked: BlockedData[] = fastify.db.getAllBlockedUsers() ?? [];
|
||||||
if (!UserAskingToBlock || !UserToBlock || !usersBlocked) return;
|
if (!UserAskingToBlock || !UserToBlock || !usersBlocked) return;
|
||||||
const userAreBlocked: boolean = isBlocked(UserAskingToBlock, UserToBlock, usersBlocked);
|
const userAreBlocked: boolean = isBlocked(UserAskingToBlock, UserToBlock, usersBlocked);
|
||||||
if(isUser_BlockedBy_me(fastify, UserAskingToBlock!.id, UserToBlock!.id)) {
|
if (isUser_BlockedBy_me(fastify, UserAskingToBlock!.id, UserToBlock!.id)) {
|
||||||
const message: blockedUnBlocked =
|
const message: blockedUnBlocked = {
|
||||||
{
|
userState: 'un-block',
|
||||||
userState: "un-block",
|
userTarget: '',
|
||||||
userTarget: "",
|
by: '',
|
||||||
by: "",
|
};
|
||||||
|
socket.emit('blockBtn', message);
|
||||||
};
|
}
|
||||||
socket.emit('blockBtn', message);
|
else {
|
||||||
} else {
|
const message: blockedUnBlocked = {
|
||||||
|
userState: 'block',
|
||||||
const message: blockedUnBlocked =
|
userTarget: UserToBlock.name,
|
||||||
{
|
by: UserAskingToBlock.name,
|
||||||
userState: "block",
|
};
|
||||||
userTarget: UserToBlock.name,
|
socket.emit('blockBtn', message);
|
||||||
by: UserAskingToBlock.name,
|
|
||||||
|
|
||||||
};
|
|
||||||
socket.emit('blockBtn', message);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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();
|
||||||
|
|
@ -579,7 +527,7 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
text: text,
|
text: text,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
SenderWindowID: socket.id,
|
SenderWindowID: socket.id,
|
||||||
Sendertext: "",
|
Sendertext: '',
|
||||||
userID: '',
|
userID: '',
|
||||||
SenderUserName: '',
|
SenderUserName: '',
|
||||||
SenderUserID: '',
|
SenderUserID: '',
|
||||||
|
|
|
||||||
|
|
@ -1,54 +1,37 @@
|
||||||
import type { ClientMessage } from './chat_types';
|
import type { ClientMessage } from './chat_types';
|
||||||
import { clientChat, color } from './app';
|
import { clientChat } from './app';
|
||||||
import { FastifyInstance } from 'fastify';
|
import { FastifyInstance } from 'fastify';
|
||||||
import type { BlockedData } from '@shared/database/mixin/blocked';
|
|
||||||
import { getUserByName } from './getUserByName';
|
import { getUserByName } from './getUserByName';
|
||||||
import type { User } from '@shared/database/mixin/user';
|
import type { User } from '@shared/database/mixin/user';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
type BlockRelation = {
|
type BlockRelation = {
|
||||||
blocked: string;
|
blocked: string;
|
||||||
blocker: string;
|
blocker: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
function whoBlockedMe(
|
function whoBlockedMe(fastify: FastifyInstance, myID: string): BlockRelation [] {
|
||||||
fastify: FastifyInstance,
|
const usersBlocked =
|
||||||
myName: string
|
|
||||||
):BlockRelation [] {
|
|
||||||
const usersBlocked =
|
|
||||||
fastify.db.getAllBlockedUsers() ?? [];
|
fastify.db.getAllBlockedUsers() ?? [];
|
||||||
|
|
||||||
return usersBlocked
|
return usersBlocked
|
||||||
.filter(entry => entry.blocked === myName)
|
.filter(entry => entry.blocked === myID)
|
||||||
.map(entry => ({
|
.map(entry => ({
|
||||||
blocked: entry.user,
|
blocked: entry.user,
|
||||||
blocker: entry.blocked,
|
blocker: entry.blocked,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export function broadcast(fastify: FastifyInstance, data: ClientMessage, sender?: string) {
|
export function broadcast(fastify: FastifyInstance, data: ClientMessage, sender?: string) {
|
||||||
|
|
||||||
const AllusersBlocked: User[] = fastify.db.getAllUsers() ?? [];
|
const AllusersBlocked: User[] = fastify.db.getAllUsers() ?? [];
|
||||||
//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 UserID = getUserByName(AllusersBlocked, data.user)?.id ?? '';
|
||||||
const list:BlockRelation[] = whoBlockedMe(fastify, UserByName);
|
const list:BlockRelation[] = whoBlockedMe(fastify, UserID);
|
||||||
|
const blockers = list.map(read => read.blocker);
|
||||||
|
const blocked = list.map(read => read.blocked);
|
||||||
|
console.log('All blockers:', blockers);
|
||||||
const blockers = list.map(read => read.blocker);
|
console.log('All blocked:', blocked);
|
||||||
const blocked = list.map(read => read.blocked);
|
// console.log(color.yellow, 'list:', list)
|
||||||
|
|
||||||
console.log('All blockers:', blockers);
|
|
||||||
console.log('All blocked:', blocked);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//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
|
||||||
|
|
@ -56,32 +39,25 @@ export function broadcast(fastify: FastifyInstance, data: ClientMessage, sender?
|
||||||
// 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) {
|
||||||
//console.log(color.yellow, `Skipping socket ${socket.id} (no user found)`);
|
// console.log(color.yellow, `Skipping socket ${socket.id} (no user found)`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// console.log('BLOCKED MAYBE', getUserById(sender));
|
// console.log('BLOCKED MAYBE', getUserById(sender));
|
||||||
// console.log('TARGET',socket.id );
|
// console.log('TARGET',socket.id );
|
||||||
// Emit structured JSON object
|
// Emit structured JSON object
|
||||||
|
// const UserID = getUserByName(AllusersBlocked, data.user)?.name ?? "";
|
||||||
const UserByName = getUserByName(AllusersBlocked, data.user)?.name ?? "";
|
// const UserByID = getUserByName(AllusersBlocked, data.user)?.id ?? "";
|
||||||
const UserByID = getUserByName(AllusersBlocked, data.user)?.id ?? "";
|
// console.log(color.blue, 'Asking:', UserID);
|
||||||
//console.log(color.blue, 'Asking:', UserByName);
|
// console.log(color.blue, 'Asking ID:', UserByID);
|
||||||
//console.log(color.blue, 'Asking ID:', UserByID);
|
|
||||||
|
|
||||||
console.log('Blocked list:', list);
|
console.log('Blocked list:', list);
|
||||||
//console.log('Sender ID:', UserByID);
|
// console.log('Sender ID:', UserByID);
|
||||||
|
|
||||||
// if (!list.includes(UserByID)) {
|
// if (!list.includes(UserByID)) {
|
||||||
// console.log('TRUE → sender NOT blocked');
|
// console.log('TRUE → sender NOT 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 });
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Debug logs
|
// Debug logs
|
||||||
// console.log(color.green, `'DEBUG LOG: Broadcast to:', ${data.command} message: ${data.text}`);
|
// console.log(color.green, `'DEBUG LOG: Broadcast to:', ${data.command} message: ${data.text}`);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import type { ClientMessage, ClientProfil } from './chat_types';
|
import type { ClientMessage } from './chat_types';
|
||||||
import { FastifyInstance } from 'fastify';
|
import { FastifyInstance } from 'fastify';
|
||||||
import type { User } from '@shared/database/mixin/user';
|
import type { User } from '@shared/database/mixin/user';
|
||||||
import { getUserById } from './getUserById';
|
import { getUserById } from './getUserById';
|
||||||
|
|
@ -15,25 +15,19 @@ export function filter_Blocked_user(fastify: FastifyInstance, data: ClientMessag
|
||||||
|
|
||||||
const users: User[] = fastify.db.getAllUsers() ?? [];
|
const users: User[] = fastify.db.getAllUsers() ?? [];
|
||||||
const UserToBlock: string = id;
|
const UserToBlock: string = id;
|
||||||
const UserAskingToBlock: User | null = getUserById(users,`${data.SenderUserID}`);
|
const UserAskingToBlock: User | null = getUserById(users, `${data.SenderUserID}`);
|
||||||
if (!UserAskingToBlock ) {
|
if (!UserAskingToBlock) {
|
||||||
// console.log('SOMETHING NULL', data);
|
// console.log('SOMETHING NULL', data);
|
||||||
// console.log('UsetToBlock', UserToBlock?.id);
|
// console.log('UsetToBlock', UserToBlock?.id);
|
||||||
// console.log('UsetToBlock', UserToBlock?.name);
|
// console.log('UsetToBlock', UserToBlock?.name);
|
||||||
// console.log('UsetAskingToBlock', UserAskingToBlock?.id);
|
// console.log('UsetAskingToBlock', UserAskingToBlock?.id);
|
||||||
// console.log('UsetAskingToBlock', UserAskingToBlock?.name);
|
// console.log('UsetAskingToBlock', UserAskingToBlock?.name);
|
||||||
console.log('');
|
|
||||||
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(isUser_BlockedBy_me(fastify, UserAskingToBlock!.id, UserToBlock))
|
if (isUser_BlockedBy_me(fastify, UserAskingToBlock!.id, UserToBlock)) {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,15 +18,21 @@ export function isUser_BlockedBy_me(fastify: FastifyInstance, blockedBy_Id : str
|
||||||
if (!users) return '';
|
if (!users) return '';
|
||||||
const UserToBlock: User | null = getUserById(users, `${isBlocked_Id}`);
|
const UserToBlock: User | null = getUserById(users, `${isBlocked_Id}`);
|
||||||
const UserAskingToBlock: User | null = getUserById(users, `${blockedBy_Id}`);
|
const UserAskingToBlock: User | null = getUserById(users, `${blockedBy_Id}`);
|
||||||
if (!UserToBlock) {console.log(color.blue, `'User: ${UserAskingToBlock?.id} has not blocked' ${isBlocked_Id}`); return ""};
|
if (!UserToBlock) {
|
||||||
if (!UserAskingToBlock) {console.log(color.blue, `'User: ${UserToBlock?.id} has not blocked by' ${blockedBy_Id}`); return ""};
|
console.log(color.blue, `'User: ${UserAskingToBlock?.id} has not blocked' ${isBlocked_Id}`);
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
if (!UserAskingToBlock) {
|
||||||
|
console.log(color.blue, `'User: ${UserToBlock?.id} has not blocked by' ${blockedBy_Id}`);
|
||||||
|
return '';
|
||||||
|
}
|
||||||
const usersBlocked: BlockedData[] = fastify.db.getAllBlockedUsers() ?? [];
|
const usersBlocked: BlockedData[] = fastify.db.getAllBlockedUsers() ?? [];
|
||||||
const userAreBlocked: boolean = isBlocked(UserAskingToBlock, UserToBlock, usersBlocked);
|
const userAreBlocked: boolean = isBlocked(UserAskingToBlock, UserToBlock, usersBlocked);
|
||||||
if (userAreBlocked) {
|
if (userAreBlocked) {
|
||||||
console.log(color.yellow, `'User :${UserAskingToBlock.name}) Hhas UN blocked ${UserToBlock.name}`)
|
console.log(color.yellow, `'User :${UserAskingToBlock.name}) Hhas UN blocked ${UserToBlock.name}`);
|
||||||
return UserAskingToBlock.name;
|
return UserAskingToBlock.name;
|
||||||
}
|
}
|
||||||
console.log(color.blue, `'User :${UserAskingToBlock.name}) has BBBblocked ${UserToBlock.name}`)
|
console.log(color.blue, `'User :${UserAskingToBlock.name}) has BBBblocked ${UserToBlock.name}`);
|
||||||
|
|
||||||
return "";
|
return '';
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import { FastifyPluginAsync } from 'fastify';
|
import { FastifyPluginAsync } from 'fastify';
|
||||||
import { Static, Type } from 'typebox';
|
import { Static, Type } from 'typebox';
|
||||||
import { broadcast } from '../broadcast';
|
|
||||||
|
|
||||||
export const ChatReq = Type.Object({
|
export const ChatReq = Type.Object({
|
||||||
message: Type.String(),
|
message: Type.String(),
|
||||||
|
|
@ -19,7 +18,7 @@ const route: FastifyPluginAsync = async (fastify): Promise<void> => {
|
||||||
config: { requireAuth: false },
|
config: { requireAuth: false },
|
||||||
},
|
},
|
||||||
async function(req, res) {
|
async function(req, res) {
|
||||||
//broadcast(this, { command: '', destination: '', user: 'CMwaLeSever!!', text: req.body.message, SenderWindowID: 'server' });
|
// broadcast(this, { command: '', destination: '', user: 'CMwaLeSever!!', text: req.body.message, SenderWindowID: 'server' });
|
||||||
void res;
|
void res;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue