summary refs log tree commit diff
path: root/gateway/src/opcodes/LazyRequest.ts
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-07-16 18:35:44 +1000
committerGitHub <noreply@github.com>2022-07-16 18:35:44 +1000
commit58c90c57f623fe6720d1097d5fbb8d6e4302289e (patch)
tree0f0ffea177dd911aee7644f09e760a1a37689ec8 /gateway/src/opcodes/LazyRequest.ts
parentRevert "Send offline group in LazyRequest (#778)" (#787) (diff)
downloadserver-58c90c57f623fe6720d1097d5fbb8d6e4302289e.tar.xz
Display offline members in member list (#788)
* Send offline member group in LazyRequest

* Better implementation of offline member group in lazy request
Diffstat (limited to '')
-rw-r--r--gateway/src/opcodes/LazyRequest.ts27
1 files changed, 24 insertions, 3 deletions
diff --git a/gateway/src/opcodes/LazyRequest.ts b/gateway/src/opcodes/LazyRequest.ts
index 2156070f..7503ee61 100644
--- a/gateway/src/opcodes/LazyRequest.ts
+++ b/gateway/src/opcodes/LazyRequest.ts
@@ -42,6 +42,8 @@ async function getMembers(guild_id: string, range: [number, number]) {
 		.flat()
 		.unique((r: Role) => r.id);
 
+	const offlineItems = [];
+
 	for (const role of member_roles) {
 		// @ts-ignore
 		const [role_members, other_members] = partition(members, (m: Member) =>
@@ -63,7 +65,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 +76,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),
 	};
 }