norm OK
This commit is contained in:
parent
1ca84b30c6
commit
c6b0225e51
5 changed files with 18 additions and 24 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import type { ClientMessage, BlockRelation} from './chat_types';
|
import type { ClientMessage, BlockRelation } from './chat_types';
|
||||||
import { clientChat } from './app';
|
import { clientChat } from './app';
|
||||||
import { FastifyInstance } from 'fastify';
|
import { FastifyInstance } from 'fastify';
|
||||||
import { getUserByName } from './getUserByName';
|
import { getUserByName } from './getUserByName';
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import type { BlockRelation} from './chat_types';
|
import type { BlockRelation } from './chat_types';
|
||||||
|
|
||||||
export function checkNamePair(list: BlockRelation[], name1: string, name2: string): (boolean) {
|
export function checkNamePair(list: BlockRelation[], name1: string, name2: string): (boolean) {
|
||||||
const matches: BlockRelation[] = [];
|
const matches: BlockRelation[] = [];
|
||||||
|
|
|
||||||
|
|
@ -24,29 +24,29 @@ export function sendInvite(fastify: FastifyInstance, innerHtml: string, profil:
|
||||||
if (clientInfo === profil.user) {
|
if (clientInfo === profil.user) {
|
||||||
profil.innerHtml = innerHtml ?? '';
|
profil.innerHtml = innerHtml ?? '';
|
||||||
if (targetSocket.id) {
|
if (targetSocket.id) {
|
||||||
|
|
||||||
const data: ClientMessage = {
|
const data: ClientMessage = {
|
||||||
command: `@${clientInfo}`,
|
command: `@${clientInfo}`,
|
||||||
destination: 'inviteMsg',
|
destination: 'inviteMsg',
|
||||||
type: "chat",
|
type: 'chat',
|
||||||
user: profil.SenderName,
|
user: profil.SenderName,
|
||||||
token: '',
|
token: '',
|
||||||
text: ' needs some text to work',
|
text: ' needs some text to work',
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
SenderWindowID: socket.id,
|
SenderWindowID: socket.id,
|
||||||
userID: '',
|
userID: '',
|
||||||
frontendUserName: '',
|
frontendUserName: '',
|
||||||
frontendUser: '',
|
frontendUser: '',
|
||||||
SenderUserName: profil.SenderName,
|
SenderUserName: profil.SenderName,
|
||||||
SenderUserID: '',
|
SenderUserID: '',
|
||||||
Sendertext: '',
|
Sendertext: '',
|
||||||
innerHtml: innerHtml,
|
innerHtml: innerHtml,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(color.yellow, 'DEBUG LOG: sendInvite Function -> sendPrivMessage :');
|
console.log(color.yellow, 'DEBUG LOG: sendInvite Function -> sendPrivMessage :');
|
||||||
sendPrivMessage(fastify, data, '');
|
sendPrivMessage(fastify, data, '');
|
||||||
|
|
||||||
|
|
||||||
// targetSocket.emit('MsgObjectServer', { message: data });
|
// targetSocket.emit('MsgObjectServer', { message: data });
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ type BlockRelation = {
|
||||||
blocker: string;
|
blocker: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
function checkNamePair(list: BlockRelation[], name1: string, name2: string): (boolean) {
|
function checkNamePair(list: BlockRelation[], name1: string, name2: string): (boolean) {
|
||||||
const matches: BlockRelation[] = [];
|
const matches: BlockRelation[] = [];
|
||||||
let exists: boolean = false;
|
let exists: boolean = false;
|
||||||
for (const item of list) {
|
for (const item of list) {
|
||||||
|
|
@ -46,7 +46,7 @@ function whoBlockedMe(fastify: FastifyInstance, myID: string): BlockRelation []
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMessage, sender?: string) {
|
export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMessage, sender?: string) {
|
||||||
|
|
||||||
const sockets = await fastify.io.fetchSockets();
|
const sockets = await fastify.io.fetchSockets();
|
||||||
const AllusersBlocked: User[] = fastify.db.getAllUsers() ?? [];
|
const AllusersBlocked: User[] = fastify.db.getAllUsers() ?? [];
|
||||||
const senderSocket = sockets.find(socket => socket.id === sender);
|
const senderSocket = sockets.find(socket => socket.id === sender);
|
||||||
|
|
@ -60,28 +60,24 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess
|
||||||
}
|
}
|
||||||
let blockMsgFlag: boolean = false;
|
let blockMsgFlag: boolean = false;
|
||||||
const UserByID = getUserByName(AllusersBlocked, clientInfo.user) ?? '';
|
const UserByID = getUserByName(AllusersBlocked, clientInfo.user) ?? '';
|
||||||
if (UserByID === ''){
|
if (UserByID === '') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const user: string = clientChat.get(socket.id)?.user ?? '';
|
const user: string = clientChat.get(socket.id)?.user ?? '';
|
||||||
const atUser = `@${user}`;
|
const atUser = `@${user}`;
|
||||||
console.log(color.red, `'DEBUG LOG:'${atUser}' '${data.command}'`)
|
|
||||||
if (atUser !== data.command || atUser === '' || data.text === '') {
|
if (atUser !== data.command || atUser === '' || data.text === '') {
|
||||||
console.log(color.red, 'DEBUG: atUser !== data.command');
|
console.log(color.red, 'DEBUG: atUser !== data.command');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(color.green, `USER ID: ${UserID} userName: ${UserByID.name} iD:${UserByID.id}`);
|
|
||||||
blockMsgFlag = checkNamePair(list, UserID, UserByID.id) || false;
|
blockMsgFlag = checkNamePair(list, UserID, UserByID.id) || false;
|
||||||
|
|
||||||
if (socket.id === sender) {
|
if (socket.id === sender) {
|
||||||
console.log(color.blue, 'sKip Sender ', socket.id);
|
console.log(color.blue, 'sKip Sender ', socket.id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
console.log(color.yellow, `blockFlag=${blockMsgFlag}: Target ${clientInfo.user}`);
|
|
||||||
if (!blockMsgFlag) {
|
if (!blockMsgFlag) {
|
||||||
console.log(color.blue, 'DEBUG Emit message: ', data.command, 'blockMsgFlag: ', blockMsgFlag);
|
|
||||||
socket.emit('MsgObjectServer', { message: data });
|
socket.emit('MsgObjectServer', { message: data });
|
||||||
if (senderSocket) {
|
if (senderSocket) {
|
||||||
senderSocket.emit('privMessageCopy', `${data.command}: ${data.text}🔒`);
|
senderSocket.emit('privMessageCopy', `${data.command}: ${data.text}🔒`);
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,14 @@
|
||||||
import { FastifyInstance } from 'fastify';
|
import { FastifyInstance } from 'fastify';
|
||||||
import type { BlockRelation} from './chat_types';
|
import type { BlockRelation } from './chat_types';
|
||||||
|
|
||||||
export function whoBlockedMe(fastify: FastifyInstance, myID: string): BlockRelation [] {
|
export function whoBlockedMe(fastify: FastifyInstance, myID: string): BlockRelation [] {
|
||||||
const usersBlocked =
|
const usersBlocked =
|
||||||
fastify.db.getAllBlockedUsers() ?? [];
|
fastify.db.getAllBlockedUsers() ?? [];
|
||||||
|
|
||||||
return usersBlocked
|
return usersBlocked
|
||||||
.filter(entry => entry.blocked === myID)
|
.filter(entry => entry.blocked === myID)
|
||||||
.map(entry => ({
|
.map(entry => ({
|
||||||
blocked: entry.user,
|
blocked: entry.user,
|
||||||
blocker: entry.blocked,
|
blocker: entry.blocked,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue