Fixed in / out chat notification system info
This commit is contained in:
parent
2e422eee2a
commit
7e644fe658
7 changed files with 28 additions and 41 deletions
|
|
@ -384,15 +384,18 @@ sendButton?.addEventListener("click", () => {
|
||||||
|
|
||||||
let toggle = false;
|
let toggle = false;
|
||||||
window.addEventListener("focus", async () => {
|
window.addEventListener("focus", async () => {
|
||||||
|
console.log('--------------------------')
|
||||||
|
console.log('Window focus called Called');
|
||||||
|
console.log('--------------------------')
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (window.__state.chatSock) connected(window.__state.chatSock);
|
if (window.__state.chatSock) connected(window.__state.chatSock);
|
||||||
}, 16);
|
}, 16);
|
||||||
if (window.location.pathname === "/app/chat") {
|
// if (window.location.pathname === "/app/chat") {
|
||||||
if (window.__state.chatSock?.id) {
|
// if (window.__state.chatSock?.id) {
|
||||||
await windowStateVisable();
|
await windowStateVisable();
|
||||||
}
|
// }
|
||||||
toggle = true;
|
toggle = true;
|
||||||
}
|
// }
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener("blur", () => {
|
window.addEventListener("blur", () => {
|
||||||
|
|
@ -419,13 +422,17 @@ sendtextbox.addEventListener("keydown", (event) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
chatButton!.addEventListener("click", () => {
|
chatButton!.addEventListener("click", async () => {
|
||||||
if (chatBox.classList.contains("hidden")) {
|
if (chatBox.classList.contains("hidden")) {
|
||||||
chatBox.classList.toggle("hidden");
|
chatBox.classList.toggle("hidden");
|
||||||
overlay.classList.add("opacity-60");
|
overlay.classList.add("opacity-60");
|
||||||
|
await windowStateVisable();
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
chatBox.classList.toggle("hidden");
|
chatBox.classList.toggle("hidden");
|
||||||
overlay.classList.remove("opacity-60");
|
overlay.classList.remove("opacity-60");
|
||||||
|
await windowStateHidden();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,14 +28,3 @@ export function addInviteMessage(text: string) {
|
||||||
chatWindow.scrollTop = chatWindow.scrollHeight;
|
chatWindow.scrollTop = chatWindow.scrollHeight;
|
||||||
return ;
|
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;
|
|
||||||
// }
|
|
||||||
|
|
@ -1,16 +1,13 @@
|
||||||
import { Socket } from "socket.io-client";
|
|
||||||
import { getSocket } from "../chat";
|
|
||||||
import { logout } from "./logout";
|
|
||||||
import { connected } from "./connected";
|
|
||||||
import { showError } from "@app/toast";
|
import { showError } from "@app/toast";
|
||||||
import { setTitle } from "@app/routing";
|
import { windowStateVisable } from "./windowStateVisable";
|
||||||
|
import { windowStateHidden } from "./windowStateHidden";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* function to quit the chat - leaves the ping-Buddies list
|
* function to quit the chat - leaves the ping-Buddies list
|
||||||
* @param socket
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export function quitChat () {
|
export async function quitChat () {
|
||||||
const chatBox = document.getElementById("chatBox")!;
|
const chatBox = document.getElementById("chatBox")!;
|
||||||
const overlay = document.querySelector('#overlay')!;
|
const overlay = document.querySelector('#overlay')!;
|
||||||
|
|
||||||
|
|
@ -18,7 +15,10 @@ export function quitChat () {
|
||||||
if (chatBox.classList.contains('hidden')) {
|
if (chatBox.classList.contains('hidden')) {
|
||||||
// chatBox.classList.toggle('hidden');
|
// chatBox.classList.toggle('hidden');
|
||||||
// overlay.classList.add('opacity-60');
|
// overlay.classList.add('opacity-60');
|
||||||
|
await windowStateVisable();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
await windowStateHidden();
|
||||||
chatBox.classList.toggle('hidden');
|
chatBox.classList.toggle('hidden');
|
||||||
overlay.classList.remove('opacity-60');
|
overlay.classList.remove('opacity-60');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
import { updateUser } from "@app/auth";
|
import { updateUser } from "@app/auth";
|
||||||
|
|
||||||
export async function windowStateHidden() {
|
export async function windowStateHidden() {
|
||||||
|
console.log('--------------------------')
|
||||||
|
console.log('WindowState Hidden Called');
|
||||||
|
console.log('--------------------------')
|
||||||
const socketId = window.__state.chatSock || undefined;
|
const socketId = window.__state.chatSock || undefined;
|
||||||
// let oldName = localStorage.getItem("oldName") ?? undefined;
|
// let oldName = localStorage.getItem("oldName") ?? undefined;
|
||||||
let oldName: string;
|
let oldName: string;
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,9 @@ import { updateUser } from "@app/auth";
|
||||||
|
|
||||||
export async function windowStateVisable() {
|
export async function windowStateVisable() {
|
||||||
|
|
||||||
|
console.log('--------------------------')
|
||||||
|
console.log('WindowState Visable Called');
|
||||||
|
console.log('--------------------------')
|
||||||
const buddies = document.getElementById('div-buddies') as HTMLDivElement;
|
const buddies = document.getElementById('div-buddies') as HTMLDivElement;
|
||||||
const socketId = window.__state.chatSock || undefined;
|
const socketId = window.__state.chatSock || undefined;
|
||||||
let oldName = localStorage.getItem("oldName") || undefined;
|
let oldName = localStorage.getItem("oldName") || undefined;
|
||||||
|
|
|
||||||
|
|
@ -174,10 +174,6 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
socket.on('privMessage', (data) => {
|
socket.on('privMessage', (data) => {
|
||||||
const clientName: string = clientChat.get(socket.id)?.user || '';
|
const clientName: string = clientChat.get(socket.id)?.user || '';
|
||||||
const prvMessage: ClientMessage = JSON.parse(data) || '';
|
const prvMessage: ClientMessage = JSON.parse(data) || '';
|
||||||
console.log("------------------------------------------------")
|
|
||||||
console.log("PRUV GAME")
|
|
||||||
console.log(data)
|
|
||||||
console.log("------------------------------------------------")
|
|
||||||
if (clientName !== null) {
|
if (clientName !== null) {
|
||||||
const obj: ClientMessage = {
|
const obj: ClientMessage = {
|
||||||
command: prvMessage.command,
|
command: prvMessage.command,
|
||||||
|
|
@ -187,7 +183,7 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
text: prvMessage.text,
|
text: prvMessage.text,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
SenderWindowID: socket.id,
|
SenderWindowID: socket.id,
|
||||||
};``
|
};
|
||||||
sendPrivMessage(fastify, obj, obj.SenderWindowID);
|
sendPrivMessage(fastify, obj, obj.SenderWindowID);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -221,11 +217,6 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
socket.on('inviteGame', async (data: string) => {
|
socket.on('inviteGame', async (data: string) => {
|
||||||
const clientName: string = clientChat.get(socket.id)?.user || '';
|
const clientName: string = clientChat.get(socket.id)?.user || '';
|
||||||
const profilInvite: ClientProfil = JSON.parse(data) || '';
|
const profilInvite: ClientProfil = JSON.parse(data) || '';
|
||||||
console.log("------------------------------------------------")
|
|
||||||
console.log("INVITE GAME")
|
|
||||||
console.log(data)
|
|
||||||
console.log("------------------------------------------------")
|
|
||||||
|
|
||||||
const linkGame: PongGameId | undefined = await setGameLink(fastify, data);
|
const linkGame: PongGameId | undefined = await setGameLink(fastify, data);
|
||||||
if (!linkGame) return;
|
if (!linkGame) return;
|
||||||
const link: string = `<a href="https://localhost:8888/app/pong?game=${linkGame}" style="color: blue; text-decoration: underline; cursor: pointer;">Click me</a>`;
|
const link: string = `<a href="https://localhost:8888/app/pong?game=${linkGame}" style="color: blue; text-decoration: underline; cursor: pointer;">Click me</a>`;
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,7 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess
|
||||||
|
|
||||||
const sockets = await fastify.io.fetchSockets();
|
const sockets = await fastify.io.fetchSockets();
|
||||||
const allUsers: User[] = fastify.db.getAllUsers() ?? [];
|
const allUsers: User[] = fastify.db.getAllUsers() ?? [];
|
||||||
console.log('sender', sender);
|
|
||||||
const senderSocket = sockets.find(socket => socket.id === sender);
|
const senderSocket = sockets.find(socket => socket.id === sender);
|
||||||
console.log('senderSOcket', senderSocket?.id);
|
|
||||||
|
|
||||||
for (const socket of sockets) {
|
for (const socket of sockets) {
|
||||||
if (socket.id === sender) continue;
|
if (socket.id === sender) continue;
|
||||||
|
|
@ -46,20 +44,16 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess
|
||||||
}
|
}
|
||||||
|
|
||||||
blockMsgFlag = checkNamePair(list, UserID, receiverUser.id) || false;
|
blockMsgFlag = checkNamePair(list, UserID, receiverUser.id) || false;
|
||||||
console.log("userID", UserID);
|
|
||||||
console.log("receiverUserID", receiverUser.id)
|
|
||||||
if (!blockMsgFlag) {
|
if (!blockMsgFlag) {
|
||||||
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) {
|
||||||
if (!data.innerHtml) {
|
if (!data.innerHtml) {
|
||||||
console.log('privMsg text');
|
|
||||||
senderSocket.emit('privMessageCopy', `${data.command}: ${data.text}🔒`);
|
senderSocket.emit('privMessageCopy', `${data.command}: ${data.text}🔒`);
|
||||||
} else {
|
}
|
||||||
console.log('privMsg texthtml');
|
else {
|
||||||
senderSocket.emit('privMessageCopy', `${data.command}: ${data.innerHtml}🔒`);
|
senderSocket.emit('privMessageCopy', `${data.command}: ${data.innerHtml}🔒`);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue