From da08497a19ab0635a8bd78e499cfc61e54352dcc Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Tue, 18 May 2021 22:04:29 +0200 Subject: :construction: WIP member list + voice --- src/opcodes/LazyRequest.ts | 47 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'src/opcodes/LazyRequest.ts') diff --git a/src/opcodes/LazyRequest.ts b/src/opcodes/LazyRequest.ts index accff8de..ba7278f0 100644 --- a/src/opcodes/LazyRequest.ts +++ b/src/opcodes/LazyRequest.ts @@ -1,10 +1,51 @@ -import { CLOSECODES, OPCODES, Payload } from "../util/Constants"; +// @ts-nocheck WIP +import { db, getPermission, MemberModel, MongooseCache, PublicUserProjection, RoleModel } from "@fosscord/server-util"; +import { LazyRequest } from "../schema/LazyRequest"; +import { OPCODES, Payload } from "../util/Constants"; import { Send } from "../util/Send"; import WebSocket from "../util/WebSocket"; +import { check } from "./instanceOf"; -export function onLazyRequest(this: WebSocket, { d }: Payload) { +// TODO: config: if want to list all members (even those who are offline) sorted by role, or just those who are online + +export async function onLazyRequest(this: WebSocket, { d }: Payload) { + return; // WIP // TODO: check data - const { guild_id, typing, channels, activities } = d; + check.call(this, LazyRequest, d); + const { guild_id, typing, channels, activities } = d as LazyRequest; + + const permissions = await getPermission(this.user_id, guild_id); + + // MongoDB query to retrieve all hoisted roles and join them with the members and users collection + const roles = await db + .collection("roles") + .aggregate([ + { $match: { guild_id, hoist: true } }, + { $sort: { position: 1 } }, + { + $lookup: { + from: "members", + let: { id: "$id" }, + pipeline: [ + { $match: { $expr: { $in: ["$$id", "$roles"] } } }, + { $limit: 1 }, + { + $lookup: { + from: "users", + let: { user_id: "$id" }, + pipeline: [ + { $match: { $expr: { $eq: ["$id", "$$user_id"] } } }, + { $project: PublicUserProjection }, + ], + as: "user", + }, + }, + ], + as: "members", + }, + }, + ]) + .toArray(); Send(this, { op: OPCODES.Dispatch, -- cgit 1.5.1