WIP no guest msg flagger
This commit is contained in:
parent
43e6ec24f5
commit
66a9947197
7 changed files with 85 additions and 7 deletions
|
|
@ -18,6 +18,7 @@
|
||||||
<div id="t-input-send" class="flex gap-1 mt-2">
|
<div id="t-input-send" class="flex gap-1 mt-2">
|
||||||
<input id="t-chat-window" placeholder="Type your message..." class="chat-window-style" />
|
<input id="t-chat-window" placeholder="Type your message..." class="chat-window-style" />
|
||||||
<div id="notify">🔕</div>
|
<div id="notify">🔕</div>
|
||||||
|
<div id="noGuest">💔</div>
|
||||||
<button id="b-send" class="send-btn-style">Send</button>
|
<button id="b-send" class="send-btn-style">Send</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -391,7 +391,9 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
|
||||||
// Send button
|
// Send button
|
||||||
sendButton?.addEventListener("click", () => {
|
sendButton?.addEventListener("click", () => {
|
||||||
const notify = document.getElementById("notify") ?? null;
|
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()) {
|
if (sendtextbox && sendtextbox.value.trim()) {
|
||||||
let msgText: string = sendtextbox.value.trim();
|
let msgText: string = sendtextbox.value.trim();
|
||||||
const msgCommand = parseCmdMsg(msgText) ?? "";
|
const msgCommand = parseCmdMsg(msgText) ?? "";
|
||||||
|
|
@ -403,17 +405,15 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
|
||||||
break;
|
break;
|
||||||
case '@block':
|
case '@block':
|
||||||
if (msgCommand[1] === '') {break;};
|
if (msgCommand[1] === '') {break;};
|
||||||
const userAskingToBlock = getUser()?.name;
|
|
||||||
if (!userAskingToBlock) return;
|
if (!userAskingToBlock) return;
|
||||||
const userID1 = getUser()?.id;
|
if (!userId) return;
|
||||||
if (!userID1) return;
|
|
||||||
const userToBlock: ClientProfil = {
|
const userToBlock: ClientProfil = {
|
||||||
command: msgCommand[0],
|
command: msgCommand[0],
|
||||||
destination: '',
|
destination: '',
|
||||||
type: 'chat',
|
type: 'chat',
|
||||||
user: msgCommand[1],
|
user: msgCommand[1],
|
||||||
loginName: '',
|
loginName: '',
|
||||||
userID: userID1,
|
userID: userId,
|
||||||
text: '',
|
text: '',
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
SenderWindowID: '',
|
SenderWindowID: '',
|
||||||
|
|
@ -433,7 +433,39 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
|
||||||
notify.innerText = '🔕';
|
notify.innerText = '🔕';
|
||||||
inviteMsgFlag = false;
|
inviteMsgFlag = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
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':
|
case '@profile':
|
||||||
if (msgCommand[1] === '') {break;};
|
if (msgCommand[1] === '') {break;};
|
||||||
getProfil(socket, msgCommand[1]);
|
getProfil(socket, msgCommand[1]);
|
||||||
|
|
|
||||||
24
frontend/src/pages/chat/chatHelperFunctions/setGuestInfo.ts
Normal file
24
frontend/src/pages/chat/chatHelperFunctions/setGuestInfo.ts
Normal 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));
|
||||||
|
}
|
||||||
|
|
@ -31,6 +31,7 @@ export type ClientProfil = {
|
||||||
SenderID: string,
|
SenderID: string,
|
||||||
Sendertext: string,
|
Sendertext: string,
|
||||||
innerHtml?: string,
|
innerHtml?: string,
|
||||||
|
guestmsg?: boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"packageManager": "pnpm@10",
|
"packageManager": "pnpm@10",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@redocly/cli": "^2.12.7",
|
"@redocly/cli": "^2.14.3",
|
||||||
"husky": "^9.1.7",
|
"husky": "^9.1.7",
|
||||||
"vite": "^7.3.0"
|
"vite": "^7.3.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@ declare module 'fastify' {
|
||||||
io: Server<{
|
io: Server<{
|
||||||
MsgObjectServer: (data: { message: ClientMessage }) => void;
|
MsgObjectServer: (data: { message: ClientMessage }) => void;
|
||||||
privMessage: (data: string) => void;
|
privMessage: (data: string) => void;
|
||||||
|
guestmsg: (data: string) => void;
|
||||||
profilMessage: (data: ClientProfil) => void;
|
profilMessage: (data: ClientProfil) => void;
|
||||||
inviteGame: (data: ClientProfil) => void;
|
inviteGame: (data: ClientProfil) => void;
|
||||||
blockUser: (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) => {
|
socket.on('profilMessage', async (data: string) => {
|
||||||
const clientName: string = clientChat.get(socket.id)?.user || '';
|
const clientName: string = clientChat.get(socket.id)?.user || '';
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ export type ClientProfil = {
|
||||||
SenderID: string,
|
SenderID: string,
|
||||||
Sendertext: string,
|
Sendertext: string,
|
||||||
innerHtml?: string,
|
innerHtml?: string,
|
||||||
|
guestmsg?: boolean,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue