implement channels fully, implement servers fully, make dms impossible

to send if no longer friends, update overview information on
invalidation (form response recieved, friends update)
This commit is contained in:
Soph :3 2026-01-11 13:47:46 +02:00
parent 92a95cb365
commit 7af96ca084
8 changed files with 245 additions and 104 deletions

View file

@ -1,7 +1,7 @@
import { json } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { _clients } from '../+server';
import { DirectMessageID } from '$lib';
import { ChannelID, DirectMessageID, UserID } from '$lib';
import { db } from '$lib/server/db';
import * as table from '$lib/server/db/schema';
import { or } from 'drizzle-orm';
@ -33,7 +33,7 @@ export const POST: RequestHandler = async ({ params, request, locals }) => {
return json({ error: 'Invalid subscribeTo value' }, { status: 400 });
}
let isValidDmid = false;
let isValid = false;
if (DirectMessageID.is(subscribeTo)) {
const find = await db
@ -47,13 +47,35 @@ export const POST: RequestHandler = async ({ params, request, locals }) => {
);
if (find?.length != 0) {
isValidDmid = true;
isValid = true;
}
}
if (UserID.is(subscribeTo)) {
const find = await db
.select()
.from(table.user)
.where(or(eq(table.user.id, subscribeTo)));
if (find?.length != 0) {
isValid = true;
}
}
if (ChannelID.is(subscribeTo)) {
const find = await db
.select()
.from(table.channel)
.where(or(eq(table.channel.id, subscribeTo)));
if (find?.length != 0) {
isValid = true;
}
}
if (
!(
isValidDmid ||
isValid ||
locals.user.groups.find((z) => z.id === subscribeTo) ||
locals.user.servers.find((z) => z.id === subscribeTo)
)