summary refs log tree commit diff
path: root/gateway/src/opcodes/LazyRequest.ts
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-24 16:35:20 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-24 16:35:20 +0200
commit2680efa34b4360f454d2807b55bcdcd0744d4328 (patch)
treeb848a20b598fbd11ca5adb12ea009795be4fd793 /gateway/src/opcodes/LazyRequest.ts
parent:construction: api (diff)
downloadserver-2680efa34b4360f454d2807b55bcdcd0744d4328.tar.xz
:construction: gateway
Diffstat (limited to 'gateway/src/opcodes/LazyRequest.ts')
-rw-r--r--gateway/src/opcodes/LazyRequest.ts70
1 files changed, 34 insertions, 36 deletions
diff --git a/gateway/src/opcodes/LazyRequest.ts b/gateway/src/opcodes/LazyRequest.ts
index 63075e5a..9f514f5f 100644
--- a/gateway/src/opcodes/LazyRequest.ts
+++ b/gateway/src/opcodes/LazyRequest.ts
@@ -18,45 +18,43 @@ export async function onLazyRequest(this: WebSocket, { d }: Payload) {
 	permissions.hasThrow("VIEW_CHANNEL");
 
 	// MongoDB query to retrieve all hoisted roles and join them with the members and users collection
-	const roles = toObject(
-		await db
-			.collection("roles")
-			.aggregate([
-				{
-					$match: {
-						guild_id,
-						// hoist: true // TODO: also match @everyone role
-					},
+	const roles = await db
+		.collection("roles")
+		.aggregate([
+			{
+				$match: {
+					guild_id,
+					// hoist: true // TODO: also match @everyone role
 				},
-				{ $sort: { position: 1 } },
-				{
-					$lookup: {
-						from: "members",
-						let: { id: "$id" },
-						pipeline: [
-							{ $match: { $expr: { $in: ["$$id", "$roles"] } } },
-							{ $limit: 100 },
-							{
-								$lookup: {
-									from: "users",
-									let: { user_id: "$id" },
-									pipeline: [
-										{ $match: { $expr: { $eq: ["$id", "$$user_id"] } } },
-										{ $project: PublicUserProjection },
-									],
-									as: "user",
-								},
-							},
-							{
-								$unwind: "$user",
+			},
+			{ $sort: { position: 1 } },
+			{
+				$lookup: {
+					from: "members",
+					let: { id: "$id" },
+					pipeline: [
+						{ $match: { $expr: { $in: ["$$id", "$roles"] } } },
+						{ $limit: 100 },
+						{
+							$lookup: {
+								from: "users",
+								let: { user_id: "$id" },
+								pipeline: [
+									{ $match: { $expr: { $eq: ["$id", "$$user_id"] } } },
+									{ $project: PublicUserProjection },
+								],
+								as: "user",
 							},
-						],
-						as: "members",
-					},
+						},
+						{
+							$unwind: "$user",
+						},
+					],
+					as: "members",
 				},
-			])
-			.toArray()
-	);
+			},
+		])
+		.toArray();
 
 	const groups = roles.map((x) => ({ id: x.id === guild_id ? "online" : x.id, count: x.members.length }));
 	const member_count = roles.reduce((a, b) => b.members.length + a, 0);