Added possibility for members to block broadcast messages from guests
This commit is contained in:
parent
2b9613fbfb
commit
df192cf227
5 changed files with 33 additions and 32 deletions
|
|
@ -18,7 +18,7 @@ import { blockUser } from './chatHelperFunctions/blockUser';
|
|||
|
||||
const MAX_SYSTEM_MESSAGES = 10;
|
||||
let inviteMsgFlag: boolean = false;
|
||||
export let noGuestFlag: boolean = false;
|
||||
export let noGuestFlag: boolean = true;
|
||||
const machineHostName = window.location.hostname;
|
||||
|
||||
export let __socket: Socket | undefined = undefined;
|
||||
|
|
@ -227,7 +227,25 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
|
|||
};
|
||||
socket.emit('message', JSON.stringify(message));
|
||||
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");
|
||||
messageElement.textContent = `${user}: is connected au server`;
|
||||
systemWindow.appendChild(messageElement);
|
||||
|
|
@ -442,18 +460,18 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
|
|||
break;
|
||||
|
||||
case '@guest':
|
||||
if (!userId) return;
|
||||
if (!userAskingToBlock) return;
|
||||
if (!userId) {return;};
|
||||
if (!userAskingToBlock) {return;};
|
||||
if (noGuest === null) {break;};
|
||||
const guest = getUser()?.guest;
|
||||
if (noGuestFlag === false) {
|
||||
if (noGuestFlag === false && noGuest.innerText === '💔') {
|
||||
noGuest.innerText = '❤️';
|
||||
noGuestFlag = true;
|
||||
} else {
|
||||
noGuest.innerText = '💔';
|
||||
noGuestFlag = false;
|
||||
}
|
||||
if (guest) {noGuestFlag = false; noGuest.innerText = ''; sendtextbox.value = '';};
|
||||
if (guest) {noGuestFlag = true; noGuest.innerText = ''; sendtextbox.value = '';};
|
||||
const userProfile: ClientProfil = {
|
||||
command: '@noguest',
|
||||
destination: '',
|
||||
|
|
@ -486,6 +504,10 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
|
|||
addMessage('\'@cls\' - clear chat screen conversations');
|
||||
addMessage('\'@profile <name>\' - pulls ups user profile');
|
||||
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('\'@quit\' - disconnect user from the chat');
|
||||
addMessage('** *********************************** **');
|
||||
|
|
|
|||
|
|
@ -211,9 +211,8 @@ export const UserImpl: Omit<IUserDb, keyof Database> = {
|
|||
getGuestMessage(this: IUserDb, id: UserId): boolean | undefined {
|
||||
const result = this.prepare('SELECT allow_guest_message FROM user WHERE id = @id').get({ id }) as {
|
||||
allow_guest_message: number
|
||||
} | undefined
|
||||
|
||||
return Boolean(result?.allow_guest_message)
|
||||
} | undefined;
|
||||
return Boolean(result?.allow_guest_message);
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -263,28 +263,15 @@ async function onReady(fastify: FastifyInstance) {
|
|||
const user: User | null = getUserByName(users, clientName);
|
||||
if (!user) return;
|
||||
if (clientName !== null) {
|
||||
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
//console.log('Data FALSE', clientName);
|
||||
console.log(user?.name);
|
||||
console.log(user?.guest);
|
||||
console.log(user?.allow_guest_message);
|
||||
else {
|
||||
fastify.db.denyGuestMessage(user?.id);
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
socket.on('profilMessage', async (data: string) => {
|
||||
const clientName: string = clientChat.get(socket.id)?.user || '';
|
||||
const profilMessage: ClientMessage = JSON.parse(data) || '';
|
||||
|
|
|
|||
|
|
@ -31,8 +31,6 @@ export async function broadcast(fastify: FastifyInstance, data: ClientMessage, s
|
|||
if (!user?.id) return;
|
||||
const guestflag: User | null = getUserByName(Allusers, clientInfo.user);
|
||||
if (!guestflag) return;
|
||||
console.log('G Flag Allow:', guestflag?.allow_guest_message);
|
||||
console.log('User:', guestflag?.name);
|
||||
const boolGuestMsg = fastify.db.getGuestMessage(guestflag?.id);
|
||||
if (!boolGuestMsg) continue;
|
||||
if (!blockMsgFlag) {
|
||||
|
|
|
|||
|
|
@ -58,7 +58,6 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess
|
|||
}
|
||||
let blockMsgFlag: boolean = false;
|
||||
const UserByID = getUserByName(allUsers, clientInfo.user) ?? '';
|
||||
const userfiche: User | null = getUserByName(allUsers, clientInfo.user);
|
||||
if (UserByID === '') {
|
||||
return;
|
||||
}
|
||||
|
|
@ -73,10 +72,6 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess
|
|||
if (socket.id === sender) {
|
||||
continue;
|
||||
}
|
||||
if (!userfiche?.id) return;
|
||||
const boolGuestMsg = fastify.db.getGuestMessage(userfiche?.id);
|
||||
if (!boolGuestMsg&& userfiche.guest) continue;
|
||||
|
||||
if (!blockMsgFlag) {
|
||||
socket.emit('MsgObjectServer', { message: data });
|
||||
fastify.log.info({ senderID: `${UserID}`, msgPriv: data.text, target: `${UserByID.id}` });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue