reset drizzle, get DMs working (partly, usernames aren't resolved)

This commit is contained in:
Soph :3 2026-01-04 23:13:39 +02:00
parent 3a0f096ade
commit bf679f9ee0
32 changed files with 1150 additions and 2867 deletions

View file

@ -4,6 +4,7 @@ import { sha256 } from '@oslojs/crypto/sha2';
import { encodeBase64url, encodeHexLowerCase } from '@oslojs/encoding';
import { db } from '$lib/server/db';
import * as table from '$lib/server/db/schema';
import { _findDmId } from '../../routes/api/messages/[[grp_srv_dm]]/[[channelId]]/[[channelId]]/+server';
const DAY_IN_MS = 1000 * 60 * 60 * 24;
@ -63,15 +64,25 @@ export async function validateSessionToken(token: string) {
.set({ expiresAt: session.expiresAt })
.where(eq(table.session.id, session.id));
}
const friends = (user.friends as string[]).length
? await db
.select({
id: table.user.id,
username: table.user.username
})
.from(table.user)
.where(inArray(table.user.id, user.friends as string[]))
: [];
const friends = await Promise.all(
((user.friends as string[]).length
? await db
.select({
id: table.user.id,
username: table.user.username
})
.from(table.user)
.where(inArray(table.user.id, user.friends as string[]))
: []
).map(async (z) => {
const dmid = await _findDmId(z.id, user.id);
return {
...z,
dmId: dmid
};
})
);
const servers = (user.servers as string[]).length
? await db
@ -99,6 +110,8 @@ export async function validateSessionToken(token: string) {
.select({
id: table.friendRequest.id,
fromUser: table.friendRequest.fromUser,
fromUsername: table.friendRequest.fromUsername,
toUsername: table.friendRequest.toUsername,
toUser: table.friendRequest.toUser
})
.from(table.friendRequest)