This commit is contained in:
NigeParis 2025-12-30 17:18:56 +01:00 committed by Maix0
parent 1ca84b30c6
commit c6b0225e51
5 changed files with 18 additions and 24 deletions

View file

@ -1,4 +1,4 @@
import type { ClientMessage, BlockRelation} from './chat_types';
import type { ClientMessage, BlockRelation } from './chat_types';
import { clientChat } from './app';
import { FastifyInstance } from 'fastify';
import { getUserByName } from './getUserByName';

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

@ -24,29 +24,29 @@ export function sendInvite(fastify: FastifyInstance, innerHtml: string, profil:
if (clientInfo === profil.user) {
profil.innerHtml = innerHtml ?? '';
if (targetSocket.id) {
const data: ClientMessage = {
command: `@${clientInfo}`,
destination: 'inviteMsg',
type: "chat",
type: 'chat',
user: profil.SenderName,
token: '',
text: ' needs some text to work',
timestamp: Date.now(),
SenderWindowID: socket.id,
userID: '',
frontendUserName: '',
frontendUser: '',
userID: '',
frontendUserName: '',
frontendUser: '',
SenderUserName: profil.SenderName,
SenderUserID: '',
SenderUserID: '',
Sendertext: '',
innerHtml: innerHtml,
};
console.log(color.yellow, 'DEBUG LOG: sendInvite Function -> sendPrivMessage :');
sendPrivMessage(fastify, data, '');
// targetSocket.emit('MsgObjectServer', { message: data });

View file

@ -9,7 +9,7 @@ type BlockRelation = {
blocker: string;
};
function checkNamePair(list: BlockRelation[], name1: string, name2: string): (boolean) {
function checkNamePair(list: BlockRelation[], name1: string, name2: string): (boolean) {
const matches: BlockRelation[] = [];
let exists: boolean = false;
for (const item of list) {
@ -46,7 +46,7 @@ function whoBlockedMe(fastify: FastifyInstance, myID: string): BlockRelation []
*/
export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMessage, sender?: string) {
const sockets = await fastify.io.fetchSockets();
const AllusersBlocked: User[] = fastify.db.getAllUsers() ?? [];
const senderSocket = sockets.find(socket => socket.id === sender);
@ -60,28 +60,24 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess
}
let blockMsgFlag: boolean = false;
const UserByID = getUserByName(AllusersBlocked, clientInfo.user) ?? '';
if (UserByID === ''){
if (UserByID === '') {
return;
}
const user: string = clientChat.get(socket.id)?.user ?? '';
const atUser = `@${user}`;
console.log(color.red, `'DEBUG LOG:'${atUser}' '${data.command}'`)
if (atUser !== data.command || atUser === '' || data.text === '') {
console.log(color.red, 'DEBUG: atUser !== data.command');
continue;
}
console.log(color.green, `USER ID: ${UserID} userName: ${UserByID.name} iD:${UserByID.id}`);
blockMsgFlag = checkNamePair(list, UserID, UserByID.id) || false;
if (socket.id === sender) {
console.log(color.blue, 'sKip Sender ', socket.id);
continue;
}
console.log(color.yellow, `blockFlag=${blockMsgFlag}: Target ${clientInfo.user}`);
if (!blockMsgFlag) {
console.log(color.blue, 'DEBUG Emit message: ', data.command, 'blockMsgFlag: ', blockMsgFlag);
socket.emit('MsgObjectServer', { message: data });
if (senderSocket) {
senderSocket.emit('privMessageCopy', `${data.command}: ${data.text}🔒`);

View file

@ -1,16 +1,14 @@
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 =
fastify.db.getAllBlockedUsers() ?? [];
return usersBlocked
.filter(entry => entry.blocked === myID)
.filter(entry => entry.blocked === myID)
.map(entry => ({
blocked: entry.user,
blocker: entry.blocked,
}));
}