First Major Clean Up Done

This commit is contained in:
NigeParis 2026-01-02 15:11:34 +01:00 committed by Maix0
parent 949e5a259a
commit afd79e334c
29 changed files with 46 additions and 118 deletions

View file

@ -8,18 +8,18 @@ import * as utils from '@shared/utils';
import { Server, Socket } from 'socket.io';
import type { User } from '@shared/database/mixin/user';
import type { BlockedData } from '@shared/database/mixin/blocked';
import { broadcast } from './broadcast';
import { broadcast } from './chatBackHelperFunctions/broadcast';
import type { ClientProfil, ClientMessage, obj } from './chat_types';
import { sendPrivMessage } from './sendPrivMessage';
import { sendBlocked } from './sendBlocked';
import { sendInvite } from './sendInvite';
import { getUserByName } from './getUserByName';
import { makeProfil } from './makeProfil';
import { isBlocked } from './isBlocked';
import { sendProfil } from './sendProfil';
import { sendPrivMessage } from './chatBackHelperFunctions/sendPrivMessage';
import { sendBlocked } from './chatBackHelperFunctions/sendBlocked';
import { sendInvite } from './chatBackHelperFunctions/sendInvite';
import { getUserByName } from './chatBackHelperFunctions/getUserByName';
import { makeProfil } from './chatBackHelperFunctions/makeProfil';
import { isBlocked } from './chatBackHelperFunctions/isBlocked';
import { sendProfil } from './chatBackHelperFunctions/sendProfil';
import { setGameLink } from './setGameLink';
import { nextGame_SocketListener } from './nextGame_SocketListener';
import { list_SocketListener } from './list_SocketListener';
import { list_SocketListener } from './chatBackHelperFunctions/list_SocketListener';
// colors for console.log
export const color = {

View file

@ -1,5 +1,5 @@
import type { ClientMessage, BlockRelation } from './chat_types';
import { clientChat } from './app';
import type { ClientMessage, BlockRelation } from '../chat_types';
import { clientChat } from '../app';
import { FastifyInstance } from 'fastify';
import { getUserByName } from './getUserByName';
import type { User } from '@shared/database/mixin/user';

View file

@ -1,4 +1,4 @@
import type { BlockRelation } from './chat_types';
import type { BlockRelation } from '../chat_types';
export function checkNamePair(list: BlockRelation[], name1: string, name2: string): (boolean) {
const matches: BlockRelation[] = [];

View file

@ -1,4 +1,3 @@
// colors for console.log
export const color = {
red: '\x1b[31m',
green: '\x1b[32m',

View file

@ -1,4 +1,4 @@
import { clientChat } from './app';
import { clientChat } from '../app';
import { Server, Socket } from 'socket.io';
/**

View file

@ -1,4 +1,4 @@
import type { ClientMessage } from './chat_types';
import type { ClientMessage } from '../chat_types';
import { FastifyInstance } from 'fastify';
import type { User } from '@shared/database/mixin/user';
import { getUserById } from './getUserById';
@ -17,11 +17,6 @@ export function filter_Blocked_user(fastify: FastifyInstance, data: ClientMessag
const UserToBlock: string = id;
const UserAskingToBlock: User | null = getUserById(users, `${data.SenderUserID}`);
if (!UserAskingToBlock) {
// console.log('SOMETHING NULL', data);
// console.log('UsetToBlock', UserToBlock?.id);
// console.log('UsetToBlock', UserToBlock?.name);
// console.log('UsetAskingToBlock', UserAskingToBlock?.id);
// console.log('UsetAskingToBlock', UserAskingToBlock?.name);
return false;
}
if (isUser_BlockedBy_me(fastify, UserAskingToBlock!.id, UserToBlock)) {

View file

@ -3,7 +3,6 @@ import type { User } from '@shared/database/mixin/user';
import type { BlockedData } from '@shared/database/mixin/blocked';
import { isBlocked } from './isBlocked';
import { getUserById } from './getUserById';
import { color } from './color';
/**
* checks the Db for the two matching Ids
@ -19,20 +18,15 @@ export function isUser_BlockedBy_me(fastify: FastifyInstance, blockedBy_Id : str
const UserToBlock: User | null = getUserById(users, `${isBlocked_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 (!UserAskingToBlock) {
console.log(color.blue, `'User: ${UserToBlock?.id} has not blocked by' ${blockedBy_Id}`);
return '';
}
const usersBlocked: BlockedData[] = fastify.db.getAllBlockedUsers() ?? [];
const userAreBlocked: boolean = isBlocked(UserAskingToBlock, UserToBlock, usersBlocked);
if (userAreBlocked) {
console.log(color.yellow, `'User :${UserAskingToBlock.name}) Hhas UN blocked ${UserToBlock.name}`);
return UserAskingToBlock.name;
}
console.log(color.blue, `'User :${UserAskingToBlock.name}) has BBBblocked ${UserToBlock.name}`);
return '';
};

View file

@ -1,8 +1,7 @@
import type { FastifyInstance } from 'fastify';
import { Socket } from 'socket.io';
import { clientChat } from './app';
import { clientChat } from '../app';
import { connectedUser } from './connectedUser';
// import { color } from './app';
export function list_SocketListener(fastify: FastifyInstance, socket: Socket) {
@ -10,11 +9,8 @@ export function list_SocketListener(fastify: FastifyInstance, socket: Socket) {
const userFromFrontend = object || null;
const client = clientChat.get(socket.id) || null;
// console.log(color.red, 'DEBUG LOG: list activated', userFromFrontend, color.reset, socket.id)
if (userFromFrontend.oldUser !== userFromFrontend.user) {
// console.log(color.red, 'DEBUG LOG: list activated', userFromFrontend.oldUser, color.reset);
if (client?.user === null) {
console.log('ERROR: clientName is NULL');
return;
};
if (client) {
@ -23,5 +19,4 @@ export function list_SocketListener(fastify: FastifyInstance, socket: Socket) {
}
connectedUser(fastify.io, socket.id);
});
}

View file

@ -1,5 +1,5 @@
import { FastifyInstance } from 'fastify';
import type { ClientProfil } from './chat_types';
import type { ClientProfil } from '../chat_types';
import type { User } from '@shared/database/mixin/user';
import { getUserByName } from './getUserByName';
import { Socket } from 'socket.io';

View file

@ -1,5 +1,5 @@
import type { ClientProfil } from './chat_types';
import { clientChat } from './app';
import type { ClientProfil } from '../chat_types';
import { clientChat } from '../app';
import { FastifyInstance } from 'fastify';
/**

View file

@ -1,5 +1,5 @@
import type { ClientMessage, ClientProfil } from './chat_types';
import { clientChat, color } from './app';
import type { ClientMessage, ClientProfil } from '../chat_types';
import { clientChat } from '../app';
import { FastifyInstance } from 'fastify';
import { sendPrivMessage } from './sendPrivMessage';
@ -16,15 +16,12 @@ export function sendInvite(fastify: FastifyInstance, innerHtml: string, profil:
fastify.io.fetchSockets().then((sockets) => {
let targetSocket;
for (const socket of sockets) {
console.log(color.yellow, 'DEBUG LOG: sendInvite Function');
const clientInfo: string = clientChat.get(socket.id)?.user || '';
console.log(color.green, 'AskingName=', profil.SenderName);
targetSocket = socket || null;
if (!targetSocket) continue;
if (clientInfo === profil.user) {
profil.innerHtml = innerHtml ?? '';
if (targetSocket.id) {
const data: ClientMessage = {
command: `@${clientInfo}`,
destination: 'inviteMsg',
@ -41,18 +38,8 @@ export function sendInvite(fastify: FastifyInstance, innerHtml: string, profil:
SenderUserID: '',
Sendertext: '',
innerHtml: innerHtml,
};
console.log(color.yellow, 'DEBUG LOG: sendInvite Function -> sendPrivMessage :');
sendPrivMessage(fastify, data, '');
// targetSocket.emit('MsgObjectServer', { message: data });
// targetSocket.emit('inviteGame', profil);
}
return;
}

View file

@ -1,5 +1,5 @@
import type { ClientMessage } from './chat_types';
import { clientChat, color } from './app';
import type { ClientMessage } from '../chat_types';
import { clientChat } from '../app';
import { FastifyInstance } from 'fastify';
import { getUserByName } from './getUserByName';
import type { User } from '@shared/database/mixin/user';
@ -20,7 +20,6 @@ function checkNamePair(list: BlockRelation[], name1: string, name2: string): (bo
return true;;
}
}
console.log(color.red, `'RETURN FLAG CheckNamePair ${exists}' item: ${name1} item2: ${name2}`);
}
return exists;
}
@ -55,7 +54,6 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess
const list:BlockRelation[] = whoBlockedMe(fastify, UserID);
const clientInfo = clientChat.get(socket.id);
if (!clientInfo?.user) {
console.log(color.red, `Skipping socket ${socket.id} (no user found)`);
continue;
}
let blockMsgFlag: boolean = false;
@ -67,14 +65,11 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess
const user: string = clientChat.get(socket.id)?.user ?? '';
const atUser = `@${user}`;
if (atUser !== data.command || atUser === '' || data.text === '') {
console.log(color.red, 'DEBUG: atUser !== data.command');
continue;
}
blockMsgFlag = checkNamePair(list, UserID, UserByID.id) || false;
if (socket.id === sender) {
console.log(color.blue, 'sKip Sender ', socket.id);
continue;
}
if (!blockMsgFlag) {

View file

@ -1,5 +1,5 @@
import { FastifyInstance } from 'fastify';
import type { ClientProfil } from './chat_types';
import type { ClientProfil } from '../chat_types';
/**
* function takes a user profil and sends it to the asker by window id
@ -12,7 +12,6 @@ export function sendProfil(fastify: FastifyInstance, profil: ClientProfil, Sende
fastify.io.fetchSockets().then((sockets) => {
const senderSocket = sockets.find(socket => socket.id === SenderWindowID);
if (senderSocket) {
// console.log(color.yellow, 'DEBUG LOG: profil.info:', profil.user);
senderSocket.emit('profilMessage', profil);
}
});

View file

@ -1,5 +1,5 @@
import { FastifyInstance } from 'fastify';
import type { BlockRelation } from './chat_types';
import type { BlockRelation } from '../chat_types';
export function whoBlockedMe(fastify: FastifyInstance, myID: string): BlockRelation [] {
const usersBlocked =