First Major Clean Up Done
This commit is contained in:
parent
949e5a259a
commit
afd79e334c
29 changed files with 46 additions and 118 deletions
|
|
@ -2,18 +2,18 @@ import './chat.css';
|
||||||
import { addRoute, setTitle, type RouteHandlerParams, type RouteHandlerReturn } from "@app/routing";
|
import { addRoute, setTitle, type RouteHandlerParams, type RouteHandlerReturn } from "@app/routing";
|
||||||
import { showError } from "@app/toast";
|
import { showError } from "@app/toast";
|
||||||
import authHtml from './chat.html?raw';
|
import authHtml from './chat.html?raw';
|
||||||
import client from '@app/api'
|
|
||||||
import { getUser, updateUser } from "@app/auth";
|
import { getUser, updateUser } from "@app/auth";
|
||||||
import io, { Socket } from 'socket.io-client';
|
import io, { Socket } from 'socket.io-client';
|
||||||
import { listBuddies } from './listBuddies';
|
import { listBuddies } from './chatHelperFunctions/listBuddies';
|
||||||
import { getProfil } from './getProfil';
|
import { getProfil } from './chatHelperFunctions/getProfil';
|
||||||
import { addMessage } from './addMessage';
|
import { addMessage } from './chatHelperFunctions/addMessage';
|
||||||
import { broadcastMsg } from './broadcastMsg';
|
import { broadcastMsg } from './chatHelperFunctions/broadcastMsg';
|
||||||
import { isLoggedIn } from './isLoggedIn';
|
import { isLoggedIn } from './chatHelperFunctions/isLoggedIn';
|
||||||
import type { ClientMessage, ClientProfil } from './types_front';
|
import type { ClientMessage, ClientProfil } from './types_front';
|
||||||
import { openProfilePopup } from './openProfilePopup';
|
import { openProfilePopup } from './chatHelperFunctions/openProfilePopup';
|
||||||
import { actionBtnPopUpBlock } from './actionBtnPopUpBlock';
|
import { actionBtnPopUpBlock } from './chatHelperFunctions/actionBtnPopUpBlock';
|
||||||
import { windowStateHidden } from './windowStateHidden';
|
import { windowStateHidden } from './chatHelperFunctions/windowStateHidden';
|
||||||
|
import type { blockedUnBlocked, obj } from './types_front';
|
||||||
|
|
||||||
export const color = {
|
export const color = {
|
||||||
red: 'color: red;',
|
red: 'color: red;',
|
||||||
|
|
@ -24,28 +24,6 @@ export const color = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export type blockedUnBlocked =
|
|
||||||
{
|
|
||||||
userState: string,
|
|
||||||
userTarget: string,
|
|
||||||
by: string,
|
|
||||||
};
|
|
||||||
|
|
||||||
export type obj =
|
|
||||||
{
|
|
||||||
command: string,
|
|
||||||
destination: string,
|
|
||||||
type: string,
|
|
||||||
user: string,
|
|
||||||
frontendUserName: string,
|
|
||||||
frontendUser: string,
|
|
||||||
token: string,
|
|
||||||
text: string,
|
|
||||||
timestamp: number,
|
|
||||||
SenderWindowID: string,
|
|
||||||
Sendertext: string,
|
|
||||||
};
|
|
||||||
|
|
||||||
const MAX_SYSTEM_MESSAGES = 10;
|
const MAX_SYSTEM_MESSAGES = 10;
|
||||||
let inviteMsgFlag: boolean = false;
|
let inviteMsgFlag: boolean = false;
|
||||||
|
|
||||||
|
|
@ -513,10 +491,7 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
|
||||||
SenderID: userID,
|
SenderID: userID,
|
||||||
|
|
||||||
};
|
};
|
||||||
//socket.emit('MsgObjectServer', message);
|
|
||||||
// addMessage(message.command);
|
|
||||||
socket.emit('privMessage', JSON.stringify(message));
|
socket.emit('privMessage', JSON.stringify(message));
|
||||||
// addMessage(JSON.stringify(message));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Clear the input in all cases
|
// Clear the input in all cases
|
||||||
|
|
@ -530,7 +505,6 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
|
||||||
if (chatWindow) {
|
if (chatWindow) {
|
||||||
chatWindow.innerHTML = '';
|
chatWindow.innerHTML = '';
|
||||||
}
|
}
|
||||||
//clearChatWindow(socket); //DEV testing broadcastGames
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Dev Game message button
|
// Dev Game message button
|
||||||
|
|
@ -550,12 +524,6 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
|
||||||
sendButton?.click();
|
sendButton?.click();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Whoami button to display user name addMessage(msgCommand[0]);
|
|
||||||
|
|
||||||
// bwhoami?.addEventListener('click', async () => {
|
|
||||||
// whoami(socket);
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { Socket } from 'socket.io-client';
|
import { Socket } from 'socket.io-client';
|
||||||
import type { ClientProfil } from './types_front';
|
import type { ClientProfil } from '../types_front';
|
||||||
import { blockUser } from './blockUser';
|
import { blockUser } from './blockUser';
|
||||||
|
|
||||||
export function actionBtnPopUpBlock(block: ClientProfil, senderSocket: Socket) {
|
export function actionBtnPopUpBlock(block: ClientProfil, senderSocket: Socket) {
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
import { color } from './chat';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* function adds a message to the frontend chatWindow
|
* function adds a message to the frontend chatWindow
|
||||||
* @param text
|
* @param text
|
||||||
|
|
@ -13,6 +11,5 @@ export function addMessage(text: string) {
|
||||||
messageElement.textContent = text;
|
messageElement.textContent = text;
|
||||||
chatWindow.appendChild(messageElement);
|
chatWindow.appendChild(messageElement);
|
||||||
chatWindow.scrollTop = chatWindow.scrollHeight;
|
chatWindow.scrollTop = chatWindow.scrollHeight;
|
||||||
console.log(`%c DEBUG LOG: Added new message:%c ${text}`, color.red, color.reset);
|
|
||||||
return ;
|
return ;
|
||||||
};
|
};
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
import { Socket } from 'socket.io-client';
|
import { Socket } from 'socket.io-client';
|
||||||
import type { ClientProfil } from './types_front';
|
import type { ClientProfil } from '../types_front';
|
||||||
import { getUser } from "@app/auth";
|
import { getUser } from "@app/auth";
|
||||||
|
|
||||||
|
|
||||||
export function blockUser(profil: ClientProfil, senderSocket: Socket) {
|
export function blockUser(profil: ClientProfil, senderSocket: Socket) {
|
||||||
profil.SenderName = getUser()?.name ?? '';
|
profil.SenderName = getUser()?.name ?? '';
|
||||||
if (profil.SenderName === profil.user) return;
|
if (profil.SenderName === profil.user) return;
|
||||||
// addMessage(`${profil.Sendertext}: ${profil.user}⛔`)
|
|
||||||
senderSocket.emit('blockUser', JSON.stringify(profil));
|
senderSocket.emit('blockUser', JSON.stringify(profil));
|
||||||
};
|
};
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { addMessage } from "./addMessage";
|
import { addMessage } from "./addMessage";
|
||||||
import { Socket } from 'socket.io-client';
|
import { Socket } from 'socket.io-client';
|
||||||
import { getUser } from "@app/auth";
|
import { getUser } from "@app/auth";
|
||||||
import type { ClientMessage } from "./types_front";
|
import type { ClientMessage } from "../types_front";
|
||||||
/**
|
/**
|
||||||
* function sends socket.emit to the backend to active and broadcast a message to all sockets
|
* function sends socket.emit to the backend to active and broadcast a message to all sockets
|
||||||
* echos the message with addMessage to the sender
|
* echos the message with addMessage to the sender
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import io, { Socket } from 'socket.io-client';
|
import { Socket } from 'socket.io-client';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* function clears all messages in the chat window
|
* function clears all messages in the chat window
|
||||||
|
|
@ -9,5 +9,4 @@ export function clearChatWindow(senderSocket: Socket) {
|
||||||
const chatWindow = document.getElementById("t-chatbox") as HTMLDivElement;
|
const chatWindow = document.getElementById("t-chatbox") as HTMLDivElement;
|
||||||
if (!chatWindow) return;
|
if (!chatWindow) return;
|
||||||
chatWindow.innerHTML = "";
|
chatWindow.innerHTML = "";
|
||||||
// senderSocket.emit('nextGame');
|
|
||||||
}
|
}
|
||||||
|
|
@ -19,6 +19,5 @@ export function getProfil(socket: Socket, user: string) {
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
SenderWindowID: socket.id,
|
SenderWindowID: socket.id,
|
||||||
};
|
};
|
||||||
// addMessage(JSON.stringify(profil));
|
|
||||||
socket.emit('profilMessage', JSON.stringify(profil));
|
socket.emit('profilMessage', JSON.stringify(profil));
|
||||||
}
|
}
|
||||||
|
|
@ -27,20 +27,16 @@ export async function listBuddies(socket: Socket, buddies: HTMLDivElement, listB
|
||||||
const user = getUser()?.name ?? "";
|
const user = getUser()?.name ?? "";
|
||||||
buddies.appendChild(buddiesElement);
|
buddies.appendChild(buddiesElement);
|
||||||
buddies.scrollTop = buddies.scrollHeight;
|
buddies.scrollTop = buddies.scrollHeight;
|
||||||
console.log(`Added buddies: ${bud}`);
|
|
||||||
|
|
||||||
buddiesElement.style.cursor = "pointer";
|
buddiesElement.style.cursor = "pointer";
|
||||||
buddiesElement.addEventListener("click", () => {
|
buddiesElement.addEventListener("click", () => {
|
||||||
navigator.clipboard.writeText(bud);
|
navigator.clipboard.writeText(bud);
|
||||||
if (bud !== user && user !== "") {
|
if (bud !== user && user !== "") {
|
||||||
sendtextbox.value = `@${bud}: `;
|
sendtextbox.value = `@${bud}: `;
|
||||||
console.log("Copied to clipboard:", bud);
|
|
||||||
sendtextbox.focus();
|
sendtextbox.focus();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
buddiesElement.addEventListener("dblclick", () => {
|
buddiesElement.addEventListener("dblclick", () => {
|
||||||
console.log("Open profile:", bud);
|
|
||||||
getProfil(socket, bud);
|
getProfil(socket, bud);
|
||||||
sendtextbox.value = "";
|
sendtextbox.value = "";
|
||||||
});
|
});
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import type { ClientProfil } from './types_front';
|
import type { ClientProfil } from '../types_front';
|
||||||
|
|
||||||
export async function openProfilePopup(profil: ClientProfil) {
|
export async function openProfilePopup(profil: ClientProfil) {
|
||||||
const modalname = document.getElementById("modal-name") ?? null;
|
const modalname = document.getElementById("modal-name") ?? null;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { __socket } from './chat';
|
import { __socket } from '../chat';
|
||||||
import { updateUser } from "@app/auth";
|
import { updateUser } from "@app/auth";
|
||||||
|
|
||||||
export async function windowStateHidden() {
|
export async function windowStateHidden() {
|
||||||
|
|
@ -34,6 +34,13 @@ export type ClientProfil = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export type blockedUnBlocked =
|
||||||
|
{
|
||||||
|
userState: string,
|
||||||
|
userTarget: string,
|
||||||
|
by: string,
|
||||||
|
};
|
||||||
|
|
||||||
export type obj =
|
export type obj =
|
||||||
{
|
{
|
||||||
command: string,
|
command: string,
|
||||||
|
|
|
||||||
|
|
@ -8,18 +8,18 @@ import * as utils from '@shared/utils';
|
||||||
import { Server, Socket } from 'socket.io';
|
import { Server, Socket } from 'socket.io';
|
||||||
import type { User } from '@shared/database/mixin/user';
|
import type { User } from '@shared/database/mixin/user';
|
||||||
import type { BlockedData } from '@shared/database/mixin/blocked';
|
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 type { ClientProfil, ClientMessage, obj } from './chat_types';
|
||||||
import { sendPrivMessage } from './sendPrivMessage';
|
import { sendPrivMessage } from './chatBackHelperFunctions/sendPrivMessage';
|
||||||
import { sendBlocked } from './sendBlocked';
|
import { sendBlocked } from './chatBackHelperFunctions/sendBlocked';
|
||||||
import { sendInvite } from './sendInvite';
|
import { sendInvite } from './chatBackHelperFunctions/sendInvite';
|
||||||
import { getUserByName } from './getUserByName';
|
import { getUserByName } from './chatBackHelperFunctions/getUserByName';
|
||||||
import { makeProfil } from './makeProfil';
|
import { makeProfil } from './chatBackHelperFunctions/makeProfil';
|
||||||
import { isBlocked } from './isBlocked';
|
import { isBlocked } from './chatBackHelperFunctions/isBlocked';
|
||||||
import { sendProfil } from './sendProfil';
|
import { sendProfil } from './chatBackHelperFunctions/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 './chatBackHelperFunctions/list_SocketListener';
|
||||||
|
|
||||||
// colors for console.log
|
// colors for console.log
|
||||||
export const color = {
|
export const color = {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import type { ClientMessage, BlockRelation } from './chat_types';
|
import type { ClientMessage, BlockRelation } from '../chat_types';
|
||||||
import { clientChat } from './app';
|
import { clientChat } from '../app';
|
||||||
import { FastifyInstance } from 'fastify';
|
import { FastifyInstance } from 'fastify';
|
||||||
import { getUserByName } from './getUserByName';
|
import { getUserByName } from './getUserByName';
|
||||||
import type { User } from '@shared/database/mixin/user';
|
import type { User } from '@shared/database/mixin/user';
|
||||||
|
|
@ -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) {
|
export function checkNamePair(list: BlockRelation[], name1: string, name2: string): (boolean) {
|
||||||
const matches: BlockRelation[] = [];
|
const matches: BlockRelation[] = [];
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
// colors for console.log
|
|
||||||
export const color = {
|
export const color = {
|
||||||
red: '\x1b[31m',
|
red: '\x1b[31m',
|
||||||
green: '\x1b[32m',
|
green: '\x1b[32m',
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { clientChat } from './app';
|
import { clientChat } from '../app';
|
||||||
import { Server, Socket } from 'socket.io';
|
import { Server, Socket } from 'socket.io';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import type { ClientMessage } 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';
|
||||||
|
|
@ -17,11 +17,6 @@ export function filter_Blocked_user(fastify: FastifyInstance, data: ClientMessag
|
||||||
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('UsetToBlock', UserToBlock?.id);
|
|
||||||
// console.log('UsetToBlock', UserToBlock?.name);
|
|
||||||
// console.log('UsetAskingToBlock', UserAskingToBlock?.id);
|
|
||||||
// console.log('UsetAskingToBlock', UserAskingToBlock?.name);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (isUser_BlockedBy_me(fastify, UserAskingToBlock!.id, UserToBlock)) {
|
if (isUser_BlockedBy_me(fastify, UserAskingToBlock!.id, UserToBlock)) {
|
||||||
|
|
@ -3,7 +3,6 @@ import type { User } from '@shared/database/mixin/user';
|
||||||
import type { BlockedData } from '@shared/database/mixin/blocked';
|
import type { BlockedData } from '@shared/database/mixin/blocked';
|
||||||
import { isBlocked } from './isBlocked';
|
import { isBlocked } from './isBlocked';
|
||||||
import { getUserById } from './getUserById';
|
import { getUserById } from './getUserById';
|
||||||
import { color } from './color';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* checks the Db for the two matching Ids
|
* 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 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) {
|
if (!UserToBlock) {
|
||||||
console.log(color.blue, `'User: ${UserAskingToBlock?.id} has not blocked' ${isBlocked_Id}`);
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
if (!UserAskingToBlock) {
|
if (!UserAskingToBlock) {
|
||||||
console.log(color.blue, `'User: ${UserToBlock?.id} has not blocked by' ${blockedBy_Id}`);
|
|
||||||
return '';
|
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}`);
|
|
||||||
return UserAskingToBlock.name;
|
return UserAskingToBlock.name;
|
||||||
}
|
}
|
||||||
console.log(color.blue, `'User :${UserAskingToBlock.name}) has BBBblocked ${UserToBlock.name}`);
|
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
import type { FastifyInstance } from 'fastify';
|
import type { FastifyInstance } from 'fastify';
|
||||||
import { Socket } from 'socket.io';
|
import { Socket } from 'socket.io';
|
||||||
import { clientChat } from './app';
|
import { clientChat } from '../app';
|
||||||
import { connectedUser } from './connectedUser';
|
import { connectedUser } from './connectedUser';
|
||||||
// import { color } from './app';
|
|
||||||
|
|
||||||
export function list_SocketListener(fastify: FastifyInstance, socket: Socket) {
|
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 userFromFrontend = object || null;
|
||||||
const client = clientChat.get(socket.id) || 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) {
|
if (userFromFrontend.oldUser !== userFromFrontend.user) {
|
||||||
// console.log(color.red, 'DEBUG LOG: list activated', userFromFrontend.oldUser, color.reset);
|
|
||||||
if (client?.user === null) {
|
if (client?.user === null) {
|
||||||
console.log('ERROR: clientName is NULL');
|
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
if (client) {
|
if (client) {
|
||||||
|
|
@ -23,5 +19,4 @@ export function list_SocketListener(fastify: FastifyInstance, socket: Socket) {
|
||||||
}
|
}
|
||||||
connectedUser(fastify.io, socket.id);
|
connectedUser(fastify.io, socket.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { FastifyInstance } from 'fastify';
|
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 type { User } from '@shared/database/mixin/user';
|
||||||
import { getUserByName } from './getUserByName';
|
import { getUserByName } from './getUserByName';
|
||||||
import { Socket } from 'socket.io';
|
import { Socket } from 'socket.io';
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import type { ClientProfil } from './chat_types';
|
import type { ClientProfil } from '../chat_types';
|
||||||
import { clientChat } from './app';
|
import { clientChat } from '../app';
|
||||||
import { FastifyInstance } from 'fastify';
|
import { FastifyInstance } from 'fastify';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import type { ClientMessage, ClientProfil } from './chat_types';
|
import type { ClientMessage, ClientProfil } from '../chat_types';
|
||||||
import { clientChat, color } from './app';
|
import { clientChat } from '../app';
|
||||||
import { FastifyInstance } from 'fastify';
|
import { FastifyInstance } from 'fastify';
|
||||||
import { sendPrivMessage } from './sendPrivMessage';
|
import { sendPrivMessage } from './sendPrivMessage';
|
||||||
|
|
||||||
|
|
@ -16,15 +16,12 @@ export function sendInvite(fastify: FastifyInstance, innerHtml: string, profil:
|
||||||
fastify.io.fetchSockets().then((sockets) => {
|
fastify.io.fetchSockets().then((sockets) => {
|
||||||
let targetSocket;
|
let targetSocket;
|
||||||
for (const socket of sockets) {
|
for (const socket of sockets) {
|
||||||
console.log(color.yellow, 'DEBUG LOG: sendInvite Function');
|
|
||||||
const clientInfo: string = clientChat.get(socket.id)?.user || '';
|
const clientInfo: string = clientChat.get(socket.id)?.user || '';
|
||||||
console.log(color.green, 'AskingName=', profil.SenderName);
|
|
||||||
targetSocket = socket || null;
|
targetSocket = socket || null;
|
||||||
if (!targetSocket) continue;
|
if (!targetSocket) continue;
|
||||||
if (clientInfo === profil.user) {
|
if (clientInfo === profil.user) {
|
||||||
profil.innerHtml = innerHtml ?? '';
|
profil.innerHtml = innerHtml ?? '';
|
||||||
if (targetSocket.id) {
|
if (targetSocket.id) {
|
||||||
|
|
||||||
const data: ClientMessage = {
|
const data: ClientMessage = {
|
||||||
command: `@${clientInfo}`,
|
command: `@${clientInfo}`,
|
||||||
destination: 'inviteMsg',
|
destination: 'inviteMsg',
|
||||||
|
|
@ -41,18 +38,8 @@ export function sendInvite(fastify: FastifyInstance, innerHtml: string, profil:
|
||||||
SenderUserID: '',
|
SenderUserID: '',
|
||||||
Sendertext: '',
|
Sendertext: '',
|
||||||
innerHtml: innerHtml,
|
innerHtml: innerHtml,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(color.yellow, 'DEBUG LOG: sendInvite Function -> sendPrivMessage :');
|
|
||||||
sendPrivMessage(fastify, data, '');
|
sendPrivMessage(fastify, data, '');
|
||||||
|
|
||||||
|
|
||||||
// targetSocket.emit('MsgObjectServer', { message: data });
|
|
||||||
|
|
||||||
|
|
||||||
// targetSocket.emit('inviteGame', profil);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
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 { getUserByName } from './getUserByName';
|
import { getUserByName } from './getUserByName';
|
||||||
import type { User } from '@shared/database/mixin/user';
|
import type { User } from '@shared/database/mixin/user';
|
||||||
|
|
@ -20,7 +20,6 @@ function checkNamePair(list: BlockRelation[], name1: string, name2: string): (bo
|
||||||
return true;;
|
return true;;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(color.red, `'RETURN FLAG CheckNamePair ${exists}' item: ${name1} item2: ${name2}`);
|
|
||||||
}
|
}
|
||||||
return exists;
|
return exists;
|
||||||
}
|
}
|
||||||
|
|
@ -55,7 +54,6 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess
|
||||||
const list:BlockRelation[] = whoBlockedMe(fastify, UserID);
|
const list:BlockRelation[] = whoBlockedMe(fastify, UserID);
|
||||||
const clientInfo = clientChat.get(socket.id);
|
const clientInfo = clientChat.get(socket.id);
|
||||||
if (!clientInfo?.user) {
|
if (!clientInfo?.user) {
|
||||||
console.log(color.red, `Skipping socket ${socket.id} (no user found)`);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let blockMsgFlag: boolean = false;
|
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 user: string = clientChat.get(socket.id)?.user ?? '';
|
||||||
const atUser = `@${user}`;
|
const atUser = `@${user}`;
|
||||||
if (atUser !== data.command || atUser === '' || data.text === '') {
|
if (atUser !== data.command || atUser === '' || data.text === '') {
|
||||||
console.log(color.red, 'DEBUG: atUser !== data.command');
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
blockMsgFlag = checkNamePair(list, UserID, UserByID.id) || false;
|
blockMsgFlag = checkNamePair(list, UserID, UserByID.id) || false;
|
||||||
|
|
||||||
if (socket.id === sender) {
|
if (socket.id === sender) {
|
||||||
console.log(color.blue, 'sKip Sender ', socket.id);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!blockMsgFlag) {
|
if (!blockMsgFlag) {
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { FastifyInstance } from 'fastify';
|
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
|
* 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) => {
|
fastify.io.fetchSockets().then((sockets) => {
|
||||||
const senderSocket = sockets.find(socket => socket.id === SenderWindowID);
|
const senderSocket = sockets.find(socket => socket.id === SenderWindowID);
|
||||||
if (senderSocket) {
|
if (senderSocket) {
|
||||||
// console.log(color.yellow, 'DEBUG LOG: profil.info:', profil.user);
|
|
||||||
senderSocket.emit('profilMessage', profil);
|
senderSocket.emit('profilMessage', profil);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { FastifyInstance } from 'fastify';
|
import { FastifyInstance } from 'fastify';
|
||||||
import type { BlockRelation } from './chat_types';
|
import type { BlockRelation } from '../chat_types';
|
||||||
|
|
||||||
export function whoBlockedMe(fastify: FastifyInstance, myID: string): BlockRelation [] {
|
export function whoBlockedMe(fastify: FastifyInstance, myID: string): BlockRelation [] {
|
||||||
const usersBlocked =
|
const usersBlocked =
|
||||||
Loading…
Add table
Add a link
Reference in a new issue