Added block invites
This commit is contained in:
parent
69c00f909f
commit
da8298dce8
6 changed files with 66 additions and 11 deletions
|
|
@ -340,6 +340,25 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (chatWindow && data.message.destination === "inviteMsg") {
|
||||||
|
const messageElement = document.createElement("div-private");
|
||||||
|
const chatWindow = document.getElementById("t-chatbox") as HTMLDivElement;
|
||||||
|
messageElement.innerHTML = `🎃${data.message.SenderUserName}: ${data.message.innerHtml}`;
|
||||||
|
chatWindow.appendChild(messageElement);
|
||||||
|
chatWindow.scrollTop = chatWindow.scrollHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const MAX_SYSTEM_MESSAGES = 10;
|
const MAX_SYSTEM_MESSAGES = 10;
|
||||||
|
|
||||||
if (systemWindow && data.message.destination === "system-info") {
|
if (systemWindow && data.message.destination === "system-info") {
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ export type ClientMessage = {
|
||||||
SenderUserID: string,
|
SenderUserID: string,
|
||||||
timestamp: number,
|
timestamp: number,
|
||||||
Sendertext: string,
|
Sendertext: string,
|
||||||
|
innerHtml?: string,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -334,6 +334,7 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
|
|
||||||
const inviteHtml: string = 'invites you to a game ' + setGameLink('');
|
const inviteHtml: string = 'invites you to a game ' + setGameLink('');
|
||||||
if (clientName !== null) {
|
if (clientName !== null) {
|
||||||
|
console.log(`DEBUG LOG: clientName =${clientName}`);
|
||||||
// const testuser: User | null = getUserByName(users, profilInvite.user ?? '');
|
// const testuser: User | null = getUserByName(users, profilInvite.user ?? '');
|
||||||
// console.log(color.yellow, 'user:', testuser?.name ?? 'Guest');
|
// console.log(color.yellow, 'user:', testuser?.name ?? 'Guest');
|
||||||
sendInvite(fastify, inviteHtml, profilInvite);
|
sendInvite(fastify, inviteHtml, profilInvite);
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ export type ClientMessage = {
|
||||||
SenderUserID: string,
|
SenderUserID: string,
|
||||||
timestamp: number,
|
timestamp: number,
|
||||||
Sendertext: string,
|
Sendertext: string,
|
||||||
|
innerHtml?: string,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import type { ClientProfil } from './chat_types';
|
import type { ClientMessage, ClientProfil } from './chat_types';
|
||||||
import { clientChat, color } from './app';
|
import { clientChat, color } from './app';
|
||||||
import { FastifyInstance } from 'fastify';
|
import { FastifyInstance } from 'fastify';
|
||||||
|
import { sendPrivMessage } from './sendPrivMessage';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* function looks for the user online in the chat
|
* function looks for the user online in the chat
|
||||||
|
|
@ -15,14 +16,43 @@ 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;
|
||||||
console.log(color.yellow, 'DEBUG LOG: user online found', profil.user, 'socket', targetSocket.id);
|
|
||||||
if (clientInfo === profil.user) {
|
if (clientInfo === profil.user) {
|
||||||
profil.innerHtml = innerHtml ?? '';
|
profil.innerHtml = innerHtml ?? '';
|
||||||
if (targetSocket.id) {
|
if (targetSocket.id) {
|
||||||
targetSocket.emit('inviteGame', profil);
|
|
||||||
|
const data: ClientMessage = {
|
||||||
|
command: `@${clientInfo}`,
|
||||||
|
destination: 'inviteMsg',
|
||||||
|
type: "chat",
|
||||||
|
user: profil.SenderName,
|
||||||
|
token: '',
|
||||||
|
text: ' needs this to work',
|
||||||
|
timestamp: Date.now(),
|
||||||
|
SenderWindowID: socket.id,
|
||||||
|
userID: '',
|
||||||
|
frontendUserName: '',
|
||||||
|
frontendUser: '',
|
||||||
|
SenderUserName: profil.SenderName,
|
||||||
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ type BlockRelation = {
|
||||||
blocker: string;
|
blocker: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
function checkNamePair(list: BlockRelation[], name1: string, name2: string): (boolean) {
|
function checkNamePair(list: BlockRelation[], name1: string, name2: string): (boolean) {
|
||||||
const matches: BlockRelation[] = [];
|
const matches: BlockRelation[] = [];
|
||||||
let exists: boolean = false;
|
let exists: boolean = false;
|
||||||
for (const item of list) {
|
for (const item of list) {
|
||||||
|
|
@ -60,17 +60,20 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess
|
||||||
}
|
}
|
||||||
let blockMsgFlag: boolean = false;
|
let blockMsgFlag: boolean = false;
|
||||||
const UserByID = getUserByName(AllusersBlocked, clientInfo.user) ?? '';
|
const UserByID = getUserByName(AllusersBlocked, clientInfo.user) ?? '';
|
||||||
if (UserByID === '') return;
|
if (UserByID === ''){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const user: string = clientChat.get(socket.id)?.user ?? '';
|
const user: string = clientChat.get(socket.id)?.user ?? '';
|
||||||
const atUser = `@${user}`;
|
const atUser = `@${user}`;
|
||||||
|
console.log(color.red, `'DEBUG LOG:'${atUser}' '${data.command}'`)
|
||||||
if (atUser !== data.command || atUser === '' || data.text === '') {
|
if (atUser !== data.command || atUser === '' || data.text === '') {
|
||||||
|
console.log(color.red, 'DEBUG: atUser !== data.command');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(color.green, `USER ID: ${UserID} userName: ${UserByID.name} iD:${UserByID.id}`);
|
||||||
blockMsgFlag = checkNamePair(list, UserID, UserByID.id) || false;
|
blockMsgFlag = checkNamePair(list, UserID, UserByID.id) || false;
|
||||||
console.log(color.green, `USER ID: ${UserID} data.user: ${data.user} blockFlag: ${blockMsgFlag} userName: ${UserByID.name} iD:${UserByID.id}`);
|
|
||||||
|
|
||||||
if (socket.id === sender) {
|
if (socket.id === sender) {
|
||||||
console.log(color.blue, 'sKip Sender ', socket.id);
|
console.log(color.blue, 'sKip Sender ', socket.id);
|
||||||
|
|
@ -78,7 +81,7 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess
|
||||||
}
|
}
|
||||||
console.log(color.yellow, `blockFlag=${blockMsgFlag}: Target ${clientInfo.user}`);
|
console.log(color.yellow, `blockFlag=${blockMsgFlag}: Target ${clientInfo.user}`);
|
||||||
if (!blockMsgFlag) {
|
if (!blockMsgFlag) {
|
||||||
console.log(color.blue, 'Emit message: ', data.command, 'blockMsgFlag: ', blockMsgFlag);
|
console.log(color.blue, 'DEBUG Emit message: ', data.command, 'blockMsgFlag: ', blockMsgFlag);
|
||||||
socket.emit('MsgObjectServer', { message: data });
|
socket.emit('MsgObjectServer', { message: data });
|
||||||
if (senderSocket) {
|
if (senderSocket) {
|
||||||
senderSocket.emit('privMessageCopy', `${data.command}: ${data.text}🔒`);
|
senderSocket.emit('privMessageCopy', `${data.command}: ${data.text}🔒`);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue