WIP copy U Game link to sender
This commit is contained in:
parent
ed2885f19d
commit
432fd849b8
4 changed files with 47 additions and 10 deletions
|
|
@ -17,7 +17,7 @@ import authHtml from "./chat.html?raw";
|
||||||
import { getUser } from "@app/auth";
|
import { getUser } from "@app/auth";
|
||||||
import { listBuddies } from "./chatHelperFunctions/listBuddies";
|
import { listBuddies } from "./chatHelperFunctions/listBuddies";
|
||||||
import { getProfil } from "./chatHelperFunctions/getProfil";
|
import { getProfil } from "./chatHelperFunctions/getProfil";
|
||||||
import { addMessage } from "./chatHelperFunctions/addMessage";
|
import { addInviteMessage, addMessage } from "./chatHelperFunctions/addMessage";
|
||||||
import { broadcastMsg } from "./chatHelperFunctions/broadcastMsg";
|
import { broadcastMsg } from "./chatHelperFunctions/broadcastMsg";
|
||||||
import { openProfilePopup } from "./chatHelperFunctions/openProfilePopup";
|
import { openProfilePopup } from "./chatHelperFunctions/openProfilePopup";
|
||||||
import { actionBtnPopUpBlock } from "./chatHelperFunctions/actionBtnPopUpBlock";
|
import { actionBtnPopUpBlock } from "./chatHelperFunctions/actionBtnPopUpBlock";
|
||||||
|
|
@ -209,7 +209,13 @@ function initChatSocket() {
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("privMessageCopy", (message: string) => {
|
socket.on("privMessageCopy", (message: string) => {
|
||||||
addMessage(message);
|
const htmlBaliseRegex = /<a\b[^>]*>[\s\S]*?<\/a>/;
|
||||||
|
const htmlBaliseMatch = message.match(htmlBaliseRegex);
|
||||||
|
|
||||||
|
if (htmlBaliseMatch)
|
||||||
|
addInviteMessage(message);
|
||||||
|
else
|
||||||
|
addMessage(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
//receives broadcast of the next GAME
|
//receives broadcast of the next GAME
|
||||||
|
|
|
||||||
|
|
@ -13,3 +13,29 @@ export function addMessage(text: string) {
|
||||||
chatWindow.scrollTop = chatWindow.scrollHeight;
|
chatWindow.scrollTop = chatWindow.scrollHeight;
|
||||||
return ;
|
return ;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export function addInviteMessage(text: string) {
|
||||||
|
const htmlBaliseRegex = new RegExp(/<a\b[^>]*>[\s\S]*?<\/a>/g);
|
||||||
|
const htmlBaliseMatch = text.match(htmlBaliseRegex);
|
||||||
|
|
||||||
|
if (!htmlBaliseMatch) return;
|
||||||
|
const chatWindow = document.getElementById("t-chatbox") as HTMLDivElement;
|
||||||
|
if (!chatWindow) return;
|
||||||
|
const messageElement = document.createElement("div-test");
|
||||||
|
messageElement.innerHTML = `🏓${text.replaceAll(htmlBaliseRegex, "").replaceAll("🔒", '').replaceAll("invites you", "You have invited")}${htmlBaliseMatch[0]}🔒`
|
||||||
|
chatWindow.appendChild(messageElement);
|
||||||
|
chatWindow.scrollTop = chatWindow.scrollHeight;
|
||||||
|
return ;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
// }
|
||||||
|
|
@ -25,6 +25,11 @@ function getGameNumber():string {
|
||||||
export async function sendInvite(fastify: FastifyInstance, innerHtml: string, profil: ClientProfil) {
|
export async function sendInvite(fastify: FastifyInstance, innerHtml: string, profil: ClientProfil) {
|
||||||
const sockets = await fastify.io.fetchSockets();
|
const sockets = await fastify.io.fetchSockets();
|
||||||
let targetSocket;
|
let targetSocket;
|
||||||
|
const senderSocket = sockets.find(socket => {
|
||||||
|
const clientInfo = clientChat.get(socket.id);
|
||||||
|
|
||||||
|
return clientInfo?.user === profil.SenderName
|
||||||
|
});
|
||||||
for (const socket of sockets) {
|
for (const socket of sockets) {
|
||||||
const clientInfo: string | undefined = clientChat.get(socket.id)?.user || undefined;
|
const clientInfo: string | undefined = clientChat.get(socket.id)?.user || undefined;
|
||||||
targetSocket = socket || null;
|
targetSocket = socket || null;
|
||||||
|
|
@ -33,23 +38,19 @@ export async function sendInvite(fastify: FastifyInstance, innerHtml: string, pr
|
||||||
profil.innerHtml = innerHtml ?? '';
|
profil.innerHtml = innerHtml ?? '';
|
||||||
if (targetSocket.id) {
|
if (targetSocket.id) {
|
||||||
const data: ClientMessage = {
|
const data: ClientMessage = {
|
||||||
|
...profil,
|
||||||
command: `@${clientInfo}`,
|
command: `@${clientInfo}`,
|
||||||
destination: 'inviteMsg',
|
destination: 'inviteMsg',
|
||||||
type: 'chat',
|
type: 'chat',
|
||||||
user: profil.user,
|
user: profil.user,
|
||||||
token: '',
|
|
||||||
text: getGameNumber(),
|
text: getGameNumber(),
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
SenderWindowID: socket.id,
|
SenderWindowID: socket.id,
|
||||||
userID: profil.userID,
|
userID: profil.userID,
|
||||||
frontendUserName: '',
|
|
||||||
frontendUser: '',
|
|
||||||
SenderUserName: profil.SenderName,
|
SenderUserName: profil.SenderName,
|
||||||
SenderUserID: '',
|
|
||||||
Sendertext: '',
|
|
||||||
innerHtml: innerHtml,
|
innerHtml: innerHtml,
|
||||||
};
|
};
|
||||||
sendPrivMessage(fastify, data, '');
|
sendPrivMessage(fastify, data, senderSocket?.id);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,11 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess
|
||||||
socket.emit('MsgObjectServer', { message: data });
|
socket.emit('MsgObjectServer', { message: data });
|
||||||
fastify.log.info({ senderID: `${UserID}`, msgPriv: data.text, target: `${receiverUser.id}` });
|
fastify.log.info({ senderID: `${UserID}`, msgPriv: data.text, target: `${receiverUser.id}` });
|
||||||
if (senderSocket) {
|
if (senderSocket) {
|
||||||
senderSocket.emit('privMessageCopy', `${data.command}: ${data.text}🔒`);
|
if (!data.innerHtml)
|
||||||
|
senderSocket.emit('privMessageCopy', `${data.command}: ${data.text}🔒`);
|
||||||
|
else
|
||||||
|
senderSocket.emit('privMessageCopy', `${data.command}: ${data.innerHtml}🔒`);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue