WIP no guest msg flagger

This commit is contained in:
NigeParis 2026-01-07 15:08:15 +01:00 committed by Maix0
parent 43e6ec24f5
commit 66a9947197
7 changed files with 85 additions and 7 deletions

View file

@ -18,6 +18,7 @@
<div id="t-input-send" class="flex gap-1 mt-2">
<input id="t-chat-window" placeholder="Type your message..." class="chat-window-style" />
<div id="notify">🔕</div>
<div id="noGuest">💔</div>
<button id="b-send" class="send-btn-style">Send</button>
</div>
</div>

View file

@ -391,7 +391,9 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
// Send button
sendButton?.addEventListener("click", () => {
const notify = document.getElementById("notify") ?? null;
const noGuest = document.getElementById("guestMsg") ?? null;
const noGuest = document.getElementById("noGuest") ?? null;
const userId = getUser()?.id;
const userAskingToBlock = getUser()?.name;
if (sendtextbox && sendtextbox.value.trim()) {
let msgText: string = sendtextbox.value.trim();
const msgCommand = parseCmdMsg(msgText) ?? "";
@ -403,17 +405,15 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
break;
case '@block':
if (msgCommand[1] === '') {break;};
const userAskingToBlock = getUser()?.name;
if (!userAskingToBlock) return;
const userID1 = getUser()?.id;
if (!userID1) return;
if (!userId) return;
const userToBlock: ClientProfil = {
command: msgCommand[0],
destination: '',
type: 'chat',
user: msgCommand[1],
loginName: '',
userID: userID1,
userID: userId,
text: '',
timestamp: Date.now(),
SenderWindowID: '',
@ -433,7 +433,39 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
notify.innerText = '🔕';
inviteMsgFlag = false;
}
break;
case '@guest':
if (!userId) return;
if (!userAskingToBlock) return;
if (noGuest === null) {break;};
if (noGuestFlag === false) {
noGuest.innerText = '❤️​';
noGuestFlag = true;
} else {
noGuest.innerText = '💔';
noGuestFlag = false;
}
const userProfile: ClientProfil = {
command: '@noguest',
destination: '',
type: 'chat',
user: '',
loginName: '',
userID: userId,
text: '',
timestamp: Date.now(),
SenderWindowID: '',
SenderName: userAskingToBlock,
SenderID: '',
Sendertext: '',
innerHtml: '',
guestmsg: noGuestFlag,
}
socket.emit('guestmsg', JSON.stringify(userProfile));
break;
case '@profile':
if (msgCommand[1] === '') {break;};
getProfil(socket, msgCommand[1]);

View file

@ -0,0 +1,24 @@
import { Socket } from 'socket.io-client';
/**
* getProfil of a user
* @param socket
* @param user
* @returns
*/
export function setGuestInfo(socket: Socket, user: string, guest: boolean) {
if (!socket.connected) return;
const profilInfo = {
command: '@guestInfo',
destination: 'guestInfo',
type: "chat",
user: user,
token: document.cookie ?? "",
text: user,
timestamp: Date.now(),
SenderWindowID: socket.id,
guest: guest,
};
socket.emit('guestInfo', JSON.stringify(profilInfo));
}

View file

@ -31,6 +31,7 @@ export type ClientProfil = {
SenderID: string,
Sendertext: string,
innerHtml?: string,
guestmsg?: boolean,
};

View file

@ -16,8 +16,8 @@
"license": "ISC",
"packageManager": "pnpm@10",
"devDependencies": {
"@redocly/cli": "^2.12.7",
"@redocly/cli": "^2.14.3",
"husky": "^9.1.7",
"vite": "^7.3.0"
"vite": "^7.3.1"
}
}

View file

@ -79,6 +79,7 @@ declare module 'fastify' {
io: Server<{
MsgObjectServer: (data: { message: ClientMessage }) => void;
privMessage: (data: string) => void;
guestmsg: (data: string) => void;
profilMessage: (data: ClientProfil) => void;
inviteGame: (data: ClientProfil) => void;
blockUser: (data: ClientProfil) => void;
@ -255,6 +256,24 @@ async function onReady(fastify: FastifyInstance) {
}
});
socket.on('guestmsg', (data) => {
const clientName: string = clientChat.get(socket.id)?.user || '';
const profile: ClientProfil = JSON.parse(data) || '';
const users: User[] = fastify.db.getAllUsers() ?? [];
const user: User | null = getUserByName(users, clientName);
if (!user) return;
if (clientName !== null) {
if (profile.guestmsg) {console.log('Data TRUE:', clientName);} else {console.log('Data FALSE'); };
if(fastify.db.getGuestMessage(user?.id)) {console.log('TRUE')};
}
});
socket.on('profilMessage', async (data: string) => {
const clientName: string = clientChat.get(socket.id)?.user || '';

View file

@ -31,6 +31,7 @@ export type ClientProfil = {
SenderID: string,
Sendertext: string,
innerHtml?: string,
guestmsg?: boolean,
};