WIP block guest messages

This commit is contained in:
NigeParis 2026-01-07 18:24:07 +01:00 committed by Maix0
parent 66a9947197
commit 7178673794
4 changed files with 31 additions and 10 deletions

View file

@ -209,7 +209,11 @@ export const UserImpl: Omit<IUserDb, keyof Database> = {
},
getGuestMessage(this: IUserDb, id: UserId): boolean | undefined {
return this.prepare('SELECT allow_guest_message FROM user WHERE id = @id').get({ id }) as 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)
},
};

View file

@ -264,11 +264,16 @@ async function onReady(fastify: FastifyInstance) {
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')};
if (profile.guestmsg) {
//console.log('Data TRUE:', clientName);
//console.log(user?.id);
fastify.db.allowGuestMessage(user?.id);
}
else
{
//console.log('Data FALSE', clientName);
fastify.db.denyGuestMessage(user?.id);
};
}
});

View file

@ -8,8 +8,8 @@ import { whoBlockedMe } from './whoBlockedMe';
export async function broadcast(fastify: FastifyInstance, data: ClientMessage, sender?: string) {
const AllusersBlocked: User[] = fastify.db.getAllUsers() ?? [];
const UserID = getUserByName(AllusersBlocked, data.user)?.id ?? '';
const Allusers: User[] = fastify.db.getAllUsers() ?? [];
const UserID = getUserByName(Allusers, data.user)?.id ?? '';
const list:BlockRelation[] = whoBlockedMe(fastify, UserID);
const sockets = await fastify.io.fetchSockets();
for (const socket of sockets) {
@ -18,15 +18,22 @@ export async function broadcast(fastify: FastifyInstance, data: ClientMessage, s
continue;
}
let blockMsgFlag: boolean = false;
const UserByID = getUserByName(AllusersBlocked, clientInfo.user)?.id ?? '';
const UserByID = getUserByName(Allusers, clientInfo.user)?.id ?? '';
const user: User | null = getUserByName(Allusers, clientInfo.user);
if (UserByID === '') return;
blockMsgFlag = checkNamePair(list, data.SenderUserID, UserByID) || false;
if (socket.id === sender) {
continue;
}
if (!user?.id) return;
const boolGuestMsg = fastify.db.getGuestMessage(user?.id);
if (boolGuestMsg && user.guest) continue;
if (!blockMsgFlag) {
socket.emit('MsgObjectServer', { message: data });
socket.emit('MsgObjectServer', { message: data });
if (data.SenderUserID) {
fastify.log.info({ senderID: data.SenderUserID, msgBroadcast: data.text });
}

View file

@ -58,6 +58,7 @@ 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;
}
@ -72,6 +73,10 @@ 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}` });