WIP block guest messages
This commit is contained in:
parent
66a9947197
commit
7178673794
4 changed files with 31 additions and 10 deletions
|
|
@ -209,7 +209,11 @@ export const UserImpl: Omit<IUserDb, keyof Database> = {
|
||||||
},
|
},
|
||||||
|
|
||||||
getGuestMessage(this: IUserDb, id: UserId): boolean | undefined {
|
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)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -264,11 +264,16 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
if (!user) return;
|
if (!user) return;
|
||||||
if (clientName !== null) {
|
if (clientName !== null) {
|
||||||
|
|
||||||
if (profile.guestmsg) {console.log('Data TRUE:', clientName);} else {console.log('Data FALSE'); };
|
if (profile.guestmsg) {
|
||||||
|
//console.log('Data TRUE:', clientName);
|
||||||
|
//console.log(user?.id);
|
||||||
if(fastify.db.getGuestMessage(user?.id)) {console.log('TRUE')};
|
fastify.db.allowGuestMessage(user?.id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//console.log('Data FALSE', clientName);
|
||||||
|
fastify.db.denyGuestMessage(user?.id);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ import { whoBlockedMe } from './whoBlockedMe';
|
||||||
|
|
||||||
export async function broadcast(fastify: FastifyInstance, data: ClientMessage, sender?: string) {
|
export async function broadcast(fastify: FastifyInstance, data: ClientMessage, sender?: string) {
|
||||||
|
|
||||||
const AllusersBlocked: User[] = fastify.db.getAllUsers() ?? [];
|
const Allusers: User[] = fastify.db.getAllUsers() ?? [];
|
||||||
const UserID = getUserByName(AllusersBlocked, data.user)?.id ?? '';
|
const UserID = getUserByName(Allusers, data.user)?.id ?? '';
|
||||||
const list:BlockRelation[] = whoBlockedMe(fastify, UserID);
|
const list:BlockRelation[] = whoBlockedMe(fastify, UserID);
|
||||||
const sockets = await fastify.io.fetchSockets();
|
const sockets = await fastify.io.fetchSockets();
|
||||||
for (const socket of sockets) {
|
for (const socket of sockets) {
|
||||||
|
|
@ -18,15 +18,22 @@ export async function broadcast(fastify: FastifyInstance, data: ClientMessage, s
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let blockMsgFlag: boolean = false;
|
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;
|
if (UserByID === '') return;
|
||||||
blockMsgFlag = checkNamePair(list, data.SenderUserID, UserByID) || false;
|
blockMsgFlag = checkNamePair(list, data.SenderUserID, UserByID) || false;
|
||||||
|
|
||||||
if (socket.id === sender) {
|
if (socket.id === sender) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!user?.id) return;
|
||||||
|
const boolGuestMsg = fastify.db.getGuestMessage(user?.id);
|
||||||
|
if (boolGuestMsg && user.guest) continue;
|
||||||
if (!blockMsgFlag) {
|
if (!blockMsgFlag) {
|
||||||
socket.emit('MsgObjectServer', { message: data });
|
|
||||||
|
socket.emit('MsgObjectServer', { message: data });
|
||||||
if (data.SenderUserID) {
|
if (data.SenderUserID) {
|
||||||
fastify.log.info({ senderID: data.SenderUserID, msgBroadcast: data.text });
|
fastify.log.info({ senderID: data.SenderUserID, msgBroadcast: data.text });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
@ -72,6 +73,10 @@ 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}` });
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue