summary refs log tree commit diff
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-07-03 16:03:57 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-07-03 16:03:57 +1000
commite085b365be04261258315e63a4f237c55669bc5c (patch)
tree693794a3ab9f3e73b49bdf43228406c694b2ab0b
parentSend offline member group in LazyRequest (diff)
downloadserver-e085b365be04261258315e63a4f237c55669bc5c.tar.xz
Better implementation of offline member group in lazy request
-rw-r--r--gateway/src/opcodes/LazyRequest.ts47
1 files changed, 15 insertions, 32 deletions
diff --git a/gateway/src/opcodes/LazyRequest.ts b/gateway/src/opcodes/LazyRequest.ts
index a78745b5..7503ee61 100644
--- a/gateway/src/opcodes/LazyRequest.ts
+++ b/gateway/src/opcodes/LazyRequest.ts
@@ -42,7 +42,7 @@ async function getMembers(guild_id: string, range: [number, number]) {
 		.flat()
 		.unique((r: Role) => r.id);
 
-	const offlineMembers = [];
+	const offlineItems = [];
 
 	for (const role of member_roles) {
 		// @ts-ignore
@@ -58,12 +58,6 @@ async function getMembers(guild_id: string, range: [number, number]) {
 		groups.push(group);
 
 		for (const member of role_members) {
-			if (!member?.user?.sessions || !member.user.sessions.length) {
-				offlineMembers.push(member);
-				group.count--;
-				continue;
-			}
-
 			const roles = member.roles
 				.filter((x: Role) => x.id !== guild_id)
 				.map((x: Role) => x.id);
@@ -71,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,
@@ -82,46 +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 (offlineMembers.length) {
+	if (offlineItems.length) {
 		const group = {
-			count: offlineMembers.length,
+			count: offlineItems.length,
 			id: "offline",
 		};
 		items.push({ group });
 		groups.push(group);
 
-		for (var member of offlineMembers) {
-			const roles = member.roles
-				.filter((x: Role) => x.id !== guild_id)
-				.map((x: Role) => x.id);
-
-			const session = member.user.sessions.first();
-
-			items.push({
-				member: {
-					...member,
-					roles,
-					user: { ...member.user, sessions: undefined },
-					presence: {
-						...session,
-						activities: session?.activities || [],
-						user: { id: member.user.id },
-					}
-				}
-			})
-		}
+		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),
 	};
 }