get the whole friends system to work now
This commit is contained in:
parent
342fd30d62
commit
126acf52f3
34 changed files with 1101 additions and 40 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import type { RequestEvent } from '@sveltejs/kit';
|
||||
import { eq, inArray } from 'drizzle-orm';
|
||||
import { eq, inArray, or } from 'drizzle-orm';
|
||||
import { sha256 } from '@oslojs/crypto/sha2';
|
||||
import { encodeBase64url, encodeHexLowerCase } from '@oslojs/encoding';
|
||||
import { db } from '$lib/server/db';
|
||||
|
|
@ -94,8 +94,17 @@ export async function validateSessionToken(token: string) {
|
|||
.where(inArray(table.group.id, (user.groups as string[])))
|
||||
: [];
|
||||
|
||||
const friendRequests = await db
|
||||
.select({
|
||||
id: table.friendRequest.id,
|
||||
fromUser: table.friendRequest.fromUser,
|
||||
toUser: table.friendRequest.toUser,
|
||||
})
|
||||
.from(table.friendRequest)
|
||||
.where(or(eq(table.friendRequest.fromUser, user.id), eq(table.friendRequest.toUser, user.id)))
|
||||
|
||||
return { session, user: {...user, servers, friends, groups: groups.map(z => { return { ...z, members: (z.members as string[]).length}})} };
|
||||
|
||||
return { session, user: {...user, servers, friends, groups: groups.map(z => { return { ...z, members: (z.members as string[]).length}}), friendRequests} };
|
||||
}
|
||||
|
||||
export type SessionValidationResult = Awaited<ReturnType<typeof validateSessionToken>>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue