summary refs log tree commit diff
path: root/src/gateway
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-10-04 23:21:50 +1100
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-10-04 23:40:05 +1100
commit7795f1b36ba03877ec222531326664661a93628a (patch)
treec5f062a76971711cbfb1abf80015cd1aaa68f3eb /src/gateway
parentMerge pull request #1099 from CyberL1/master (diff)
downloadserver-7795f1b36ba03877ec222531326664661a93628a.tar.xz
refactor channel positions in guild
Diffstat (limited to 'src/gateway')
-rw-r--r--src/gateway/opcodes/Identify.ts40
1 files changed, 27 insertions, 13 deletions
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);