Added possibility for members to block broadcast messages from guests

This commit is contained in:
NigeParis 2026-01-08 10:12:12 +01:00 committed by Maix0
parent 2b9613fbfb
commit df192cf227
5 changed files with 33 additions and 32 deletions

View file

@ -18,7 +18,7 @@ import { blockUser } from './chatHelperFunctions/blockUser';
const MAX_SYSTEM_MESSAGES = 10; const MAX_SYSTEM_MESSAGES = 10;
let inviteMsgFlag: boolean = false; let inviteMsgFlag: boolean = false;
export let noGuestFlag: boolean = false; export let noGuestFlag: boolean = true;
const machineHostName = window.location.hostname; const machineHostName = window.location.hostname;
export let __socket: Socket | undefined = undefined; export let __socket: Socket | undefined = undefined;
@ -227,7 +227,25 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
}; };
socket.emit('message', JSON.stringify(message)); socket.emit('message', JSON.stringify(message));
const guest = getUser()?.guest; const guest = getUser()?.guest;
if (guest) {noGuestFlag = false; noGuest.innerText = ''; sendtextbox.value = ''; return;}; if (guest) {noGuest.innerText = '';} else {noGuest.innerText = '❤️'};
const userProfile: ClientProfil = {
command: '@noguest',
destination: '',
type: 'chat',
user: '',
loginName: '',
userID: '',
text: '',
timestamp: Date.now(),
SenderWindowID: '',
SenderName: '',
SenderID: '',
Sendertext: '',
innerHtml: '',
guestmsg: true,
}
socket.emit('guestmsg', JSON.stringify(userProfile));
const messageElement = document.createElement("div"); const messageElement = document.createElement("div");
messageElement.textContent = `${user}: is connected au server`; messageElement.textContent = `${user}: is connected au server`;
systemWindow.appendChild(messageElement); systemWindow.appendChild(messageElement);
@ -442,18 +460,18 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
break; break;
case '@guest': case '@guest':
if (!userId) return; if (!userId) {return;};
if (!userAskingToBlock) return; if (!userAskingToBlock) {return;};
if (noGuest === null) {break;}; if (noGuest === null) {break;};
const guest = getUser()?.guest; const guest = getUser()?.guest;
if (noGuestFlag === false) { if (noGuestFlag === false && noGuest.innerText === '💔') {
noGuest.innerText = '❤️​'; noGuest.innerText = '❤️​';
noGuestFlag = true; noGuestFlag = true;
} else { } else {
noGuest.innerText = '💔'; noGuest.innerText = '💔';
noGuestFlag = false; noGuestFlag = false;
} }
if (guest) {noGuestFlag = false; noGuest.innerText = ''; sendtextbox.value = '';}; if (guest) {noGuestFlag = true; noGuest.innerText = ''; sendtextbox.value = '';};
const userProfile: ClientProfil = { const userProfile: ClientProfil = {
command: '@noguest', command: '@noguest',
destination: '', destination: '',
@ -486,6 +504,10 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
addMessage('\'@cls\' - clear chat screen conversations'); addMessage('\'@cls\' - clear chat screen conversations');
addMessage('\'@profile <name>\' - pulls ups user profile'); addMessage('\'@profile <name>\' - pulls ups user profile');
addMessage('\'@block <name>\' - blocks / unblock user'); addMessage('\'@block <name>\' - blocks / unblock user');
const guestflag = getUser()?.guest;
if(!guestflag) {
addMessage('\'@guest\' - guest broadcast msgs on / off');
}
addMessage('\'@notify\' - toggles notifications on / off'); addMessage('\'@notify\' - toggles notifications on / off');
addMessage('\'@quit\' - disconnect user from the chat'); addMessage('\'@quit\' - disconnect user from the chat');
addMessage('** *********************************** **'); addMessage('** *********************************** **');

View file

@ -211,9 +211,8 @@ export const UserImpl: Omit<IUserDb, keyof Database> = {
getGuestMessage(this: IUserDb, id: UserId): boolean | undefined { getGuestMessage(this: IUserDb, id: UserId): boolean | undefined {
const result = this.prepare('SELECT allow_guest_message FROM user WHERE id = @id').get({ id }) as { const result = this.prepare('SELECT allow_guest_message FROM user WHERE id = @id').get({ id }) as {
allow_guest_message: number allow_guest_message: number
} | undefined } | undefined;
return Boolean(result?.allow_guest_message);
return Boolean(result?.allow_guest_message)
}, },
}; };

View file

@ -263,28 +263,15 @@ async function onReady(fastify: FastifyInstance) {
const user: User | null = getUserByName(users, clientName); const user: User | null = getUserByName(users, clientName);
if (!user) return; if (!user) return;
if (clientName !== null) { if (clientName !== null) {
if (profile.guestmsg) { if (profile.guestmsg) {
//console.log('Data TRUE:', clientName);
console.log(user?.name);
console.log(user?.guest);
console.log(user?.allow_guest_message);
fastify.db.allowGuestMessage(user?.id); fastify.db.allowGuestMessage(user?.id);
} }
else else {
{
//console.log('Data FALSE', clientName);
console.log(user?.name);
console.log(user?.guest);
console.log(user?.allow_guest_message);
fastify.db.denyGuestMessage(user?.id); fastify.db.denyGuestMessage(user?.id);
}; };
} }
}); });
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 || '';
const profilMessage: ClientMessage = JSON.parse(data) || ''; const profilMessage: ClientMessage = JSON.parse(data) || '';

View file

@ -29,10 +29,8 @@ export async function broadcast(fastify: FastifyInstance, data: ClientMessage, s
} }
if (!user?.id) return; if (!user?.id) return;
const guestflag: User | null = getUserByName(Allusers,clientInfo.user); const guestflag: User | null = getUserByName(Allusers, clientInfo.user);
if (!guestflag) return; if (!guestflag) return;
console.log('G Flag Allow:', guestflag?.allow_guest_message);
console.log('User:', guestflag?.name);
const boolGuestMsg = fastify.db.getGuestMessage(guestflag?.id); const boolGuestMsg = fastify.db.getGuestMessage(guestflag?.id);
if (!boolGuestMsg) continue; if (!boolGuestMsg) continue;
if (!blockMsgFlag) { if (!blockMsgFlag) {

View file

@ -58,7 +58,6 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess
} }
let blockMsgFlag: boolean = false; let blockMsgFlag: boolean = false;
const UserByID = getUserByName(allUsers, clientInfo.user) ?? ''; const UserByID = getUserByName(allUsers, clientInfo.user) ?? '';
const userfiche: User | null = getUserByName(allUsers, clientInfo.user);
if (UserByID === '') { if (UserByID === '') {
return; return;
} }
@ -73,10 +72,6 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess
if (socket.id === sender) { if (socket.id === sender) {
continue; continue;
} }
if (!userfiche?.id) return;
const boolGuestMsg = fastify.db.getGuestMessage(userfiche?.id);
if (!boolGuestMsg&& userfiche.guest) continue;
if (!blockMsgFlag) { if (!blockMsgFlag) {
socket.emit('MsgObjectServer', { message: data }); socket.emit('MsgObjectServer', { message: data });
fastify.log.info({ senderID: `${UserID}`, msgPriv: data.text, target: `${UserByID.id}` }); fastify.log.info({ senderID: `${UserID}`, msgPriv: data.text, target: `${UserByID.id}` });