diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-07-03 15:39:00 +1000 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-07-03 15:39:00 +1000 |
commit | c9a33ce173bd83dd68443294fb01a87b19ad7670 (patch) | |
tree | 3c8c8e6e5c72751fd28b980b9cca728c71c9f337 | |
parent | Use 1:1 dms instead of group dms (diff) | |
download | server-c9a33ce173bd83dd68443294fb01a87b19ad7670.tar.xz |
Handle offline members group in LazyRequest
-rw-r--r-- | gateway/src/opcodes/LazyRequest.ts | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/gateway/src/opcodes/LazyRequest.ts b/gateway/src/opcodes/LazyRequest.ts index 2156070f..391e9169 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,38 @@ 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 }, + } + } + }) + } + } + + console.log(items, groups, range, members); + return { items, groups, |