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 { listBuddies } from "./chatHelperFunctions/listBuddies";
|
||||
import { getProfil } from "./chatHelperFunctions/getProfil";
|
||||
import { addMessage } from "./chatHelperFunctions/addMessage";
|
||||
import { addInviteMessage, addMessage } from "./chatHelperFunctions/addMessage";
|
||||
import { broadcastMsg } from "./chatHelperFunctions/broadcastMsg";
|
||||
import { openProfilePopup } from "./chatHelperFunctions/openProfilePopup";
|
||||
import { actionBtnPopUpBlock } from "./chatHelperFunctions/actionBtnPopUpBlock";
|
||||
|
|
@ -209,7 +209,13 @@ function initChatSocket() {
|
|||
});
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -12,4 +12,30 @@ export function addMessage(text: string) {
|
|||
chatWindow.appendChild(messageElement);
|
||||
chatWindow.scrollTop = chatWindow.scrollHeight;
|
||||
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) {
|
||||
const sockets = await fastify.io.fetchSockets();
|
||||
let targetSocket;
|
||||
const senderSocket = sockets.find(socket => {
|
||||
const clientInfo = clientChat.get(socket.id);
|
||||
|
||||
return clientInfo?.user === profil.SenderName
|
||||
});
|
||||
for (const socket of sockets) {
|
||||
const clientInfo: string | undefined = clientChat.get(socket.id)?.user || undefined;
|
||||
targetSocket = socket || null;
|
||||
|
|
@ -33,23 +38,19 @@ export async function sendInvite(fastify: FastifyInstance, innerHtml: string, pr
|
|||
profil.innerHtml = innerHtml ?? '';
|
||||
if (targetSocket.id) {
|
||||
const data: ClientMessage = {
|
||||
...profil,
|
||||
command: `@${clientInfo}`,
|
||||
destination: 'inviteMsg',
|
||||
type: 'chat',
|
||||
user: profil.user,
|
||||
token: '',
|
||||
text: getGameNumber(),
|
||||
timestamp: Date.now(),
|
||||
SenderWindowID: socket.id,
|
||||
userID: profil.userID,
|
||||
frontendUserName: '',
|
||||
frontendUser: '',
|
||||
SenderUserName: profil.SenderName,
|
||||
SenderUserID: '',
|
||||
Sendertext: '',
|
||||
innerHtml: innerHtml,
|
||||
};
|
||||
sendPrivMessage(fastify, data, '');
|
||||
sendPrivMessage(fastify, data, senderSocket?.id);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,11 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess
|
|||
socket.emit('MsgObjectServer', { message: data });
|
||||
fastify.log.info({ senderID: `${UserID}`, msgPriv: data.text, target: `${receiverUser.id}` });
|
||||
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