summary refs log tree commit diff
path: root/gateway
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-07-16 18:06:43 +1000
committerGitHub <noreply@github.com>2022-07-16 11:06:43 +0300
commit614cfdc85cfa8903bf7432e770bd4aba41c51b5f (patch)
tree710fb2578a1e07184950e886769ce2f4bd60f4ed /gateway
parentRelax some of the limits (diff)
downloadserver-614cfdc85cfa8903bf7432e770bd4aba41c51b5f.tar.xz
Send offline group in LazyRequest (#778)
* Send offline member group in LazyRequest

* Better implementation of offline member group in lazy request

* Always display roles separately to online members
Diffstat (limited to 'gateway')
-rw-r--r--gateway/src/opcodes/LazyRequest.ts28
1 files changed, 25 insertions, 3 deletions
diff --git a/gateway/src/opcodes/LazyRequest.ts b/gateway/src/opcodes/LazyRequest.ts
index 2156070f..2bff1fd3 100644
--- a/gateway/src/opcodes/LazyRequest.ts
+++ b/gateway/src/opcodes/LazyRequest.ts
@@ -41,6 +41,9 @@ async function getMembers(guild_id: string, range: [number, number]) {
 		.map((m) => m.roles)
 		.flat()
 		.unique((r: Role) => r.id);
+	member_roles.push(member_roles.splice(member_roles.findIndex(x => x.id == guild_id))[0]);	// move @everyone/online to bottom
+
+	const offlineItems = [];
 
 	for (const role of member_roles) {
 		// @ts-ignore
@@ -63,7 +66,7 @@ async function getMembers(guild_id: string, range: [number, number]) {
 			const session = member.user.sessions.first();
 
 			// TODO: properly mock/hide offline/invisible status
-			items.push({
+			const item = {
 				member: {
 					...member,
 					roles,
@@ -74,16 +77,35 @@ async function getMembers(guild_id: string, range: [number, number]) {
 						user: { id: member.user.id },
 					},
 				},
-			});
+			}
+
+			if (!member?.user?.sessions || !member.user.sessions.length) {
+				offlineItems.push(item);
+				group.count--;
+				continue;
+			}
+
+			items.push(item);
 		}
 		members = other_members;
 	}
 
+	if (offlineItems.length) {
+		const group = {
+			count: offlineItems.length,
+			id: "offline",
+		};
+		items.push({ group });
+		groups.push(group);
+
+		items.push(...offlineItems);
+	}
+
 	return {
 		items,
 		groups,
 		range,
-		members: items.map((x) => x.member).filter((x) => x),
+		members: items.map((x) => 'member' in x ? x.member : undefined).filter(x => !!x),
 	};
 }