From e5b0e10cc771f15128fd47309e815d0eb3915729 Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Sun, 3 Jul 2022 15:48:13 +1000 Subject: [PATCH 1/2] Send offline member group in LazyRequest --- gateway/src/opcodes/LazyRequest.ts | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/gateway/src/opcodes/LazyRequest.ts b/gateway/src/opcodes/LazyRequest.ts index 2156070f..a78745b5 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 offlineMembers = []; + for (const role of member_roles) { // @ts-ignore const [role_members, other_members] = partition(members, (m: Member) => @@ -56,6 +58,12 @@ 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); @@ -79,6 +87,36 @@ async function getMembers(guild_id: string, range: [number, number]) { members = other_members; } + if (offlineMembers.length) { + const group = { + count: offlineMembers.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 }, + } + } + }) + } + } + return { items, groups, From e085b365be04261258315e63a4f237c55669bc5c Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Sun, 3 Jul 2022 16:03:57 +1000 Subject: [PATCH 2/2] Better implementation of offline member group in lazy request --- gateway/src/opcodes/LazyRequest.ts | 47 ++++++++++-------------------- 1 file 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), }; }