diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-07-03 15:48:13 +1000 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-07-03 15:48:13 +1000 |
commit | 706831406e4e1ac04ef74acee05b3a3117867847 (patch) | |
tree | afa053da44990c954284424d13e46e8db840721e /gateway | |
parent | Merge pull request #737 from fosscord/translation (diff) | |
download | server-706831406e4e1ac04ef74acee05b3a3117867847.tar.xz |
Send offline member group in LazyRequest
Diffstat (limited to 'gateway')
-rw-r--r-- | gateway/src/opcodes/LazyRequest.ts | 38 |
1 files changed, 38 insertions, 0 deletions
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, |