From 7795f1b36ba03877ec222531326664661a93628a Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Wed, 4 Oct 2023 23:21:50 +1100 Subject: refactor channel positions in guild --- src/gateway/opcodes/Identify.ts | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'src/gateway') diff --git a/src/gateway/opcodes/Identify.ts b/src/gateway/opcodes/Identify.ts index 9a3128d9..6de5191c 100644 --- a/src/gateway/opcodes/Identify.ts +++ b/src/gateway/opcodes/Identify.ts @@ -54,6 +54,7 @@ import { UserSettings, checkToken, emitEvent, + getDatabase, } from "@spacebar/util"; import { check } from "./instanceOf"; @@ -167,7 +168,12 @@ export async function onIdentify(this: WebSocket, data: Payload) { // guild channels, emoji, roles, stickers // but we do want almost everything from guild. // How do you do that without just enumerating the guild props? - guild: true, + guild: Object.fromEntries( + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + getDatabase()! + .getMetadata(Guild) + .columns.map((x) => [x.propertyName, true]), + ), }, relations: [ "guild", @@ -253,18 +259,26 @@ export async function onIdentify(this: WebSocket, data: Payload) { const guilds: GuildOrUnavailable[] = members.map((member) => { // filter guild channels we don't have permission to view // TODO: check if this causes issues when the user is granted other roles? - member.guild.channels = member.guild.channels.filter((channel) => { - const perms = Permissions.finalPermission({ - user: { - id: member.id, - roles: member.roles.map((x) => x.id), - }, - guild: member.guild, - channel, - }); - - return perms.has("VIEW_CHANNEL"); - }); + member.guild.channels = member.guild.channels + .filter((channel) => { + const perms = Permissions.finalPermission({ + user: { + id: member.id, + roles: member.roles.map((x) => x.id), + }, + guild: member.guild, + channel, + }); + + return perms.has("VIEW_CHANNEL"); + }) + .map((channel) => { + channel.position = member.guild.channelOrdering.indexOf( + channel.id, + ); + return channel; + }) + .sort((a, b) => a.position - b.position); if (user.bot) { pending_guilds.push(member.guild); -- cgit 1.4.1