Merged with Maix Master

This commit is contained in:
NigeParis 2025-12-22 19:08:28 +01:00 committed by Maix0
parent ea023fa99a
commit 266feb22f4
9 changed files with 52 additions and 45 deletions

View file

@ -26,7 +26,7 @@
"@fastify/websocket": "^11.2.0",
"fastify": "^5.6.2",
"fastify-plugin": "^5.1.0",
"socket.io": "^4.8.1",
"socket.io": "^4.8.2",
"typebox": "^1.0.65"
},
"devDependencies": {

View file

@ -1,41 +1,11 @@
import type { ClientMessage } from './chat_types';
import type { ClientMessage, BlockRelation} from './chat_types';
import { clientChat } from './app';
import { FastifyInstance } from 'fastify';
import { getUserByName } from './getUserByName';
import type { User } from '@shared/database/mixin/user';
import { color } from './app';
type BlockRelation = {
blocked: string;
blocker: string;
};
function checkNamePair(list: BlockRelation[], name1: string, name2: string): (boolean) {
const matches: BlockRelation[] = [];
let exists: boolean = false;
for (const item of list) {
if (item.blocker === name1) {
matches.push(item);
if (item.blocked === name2) {
exists = true;
return true;;
}
}
}
return exists;
}
function whoBlockedMe(fastify: FastifyInstance, myID: string): BlockRelation [] {
const usersBlocked =
fastify.db.getAllBlockedUsers() ?? [];
return usersBlocked
.filter(entry => entry.blocked === myID)
.map(entry => ({
blocked: entry.user,
blocker: entry.blocked,
}));
}
import { checkNamePair } from './checkNamePair';
import { whoBlockedMe } from './whoBlockedMe';
export async function broadcast(fastify: FastifyInstance, data: ClientMessage, sender?: string) {

View file

@ -48,3 +48,8 @@ export type obj =
SenderWindowID: string,
Sendertext: string,
};
export type BlockRelation = {
blocked: string;
blocker: string;
};

View file

@ -0,0 +1,16 @@
import type { BlockRelation} from './chat_types';
export function checkNamePair(list: BlockRelation[], name1: string, name2: string): (boolean) {
const matches: BlockRelation[] = [];
let exists: boolean = false;
for (const item of list) {
if (item.blocker === name1) {
matches.push(item);
if (item.blocked === name2) {
exists = true;
return true;;
}
}
}
return exists;
}

View file

@ -0,0 +1,16 @@
import { FastifyInstance } from 'fastify';
import type { BlockRelation} from './chat_types';
export function whoBlockedMe(fastify: FastifyInstance, myID: string): BlockRelation [] {
const usersBlocked =
fastify.db.getAllBlockedUsers() ?? [];
return usersBlocked
.filter(entry => entry.blocked === myID)
.map(entry => ({
blocked: entry.user,
blocker: entry.blocked,
}));
}