summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--package-lock.json24
-rw-r--r--package.json2
-rw-r--r--src/gateway/opcodes/LazyRequest.ts27
3 files changed, 52 insertions, 1 deletions
diff --git a/package-lock.json b/package-lock.json
index f7a81eb0..8ce95eed 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -38,6 +38,7 @@
 				"module-alias": "^2.2.2",
 				"morgan": "^1.10.0",
 				"multer": "^1.4.5-lts.1",
+				"murmurhash-js": "^1.0.0",
 				"node-2fa": "^2.0.3",
 				"node-fetch": "^2.6.7",
 				"node-os-utils": "^1.3.7",
@@ -64,6 +65,7 @@
 				"@types/jsonwebtoken": "^8.5.9",
 				"@types/morgan": "^1.9.3",
 				"@types/multer": "^1.4.7",
+				"@types/murmurhash-js": "^1.0.4",
 				"@types/node": "^18.7.20",
 				"@types/node-fetch": "^2.6.2",
 				"@types/node-os-utils": "^1.3.0",
@@ -2017,6 +2019,12 @@
 				"@types/express": "*"
 			}
 		},
+		"node_modules/@types/murmurhash-js": {
+			"version": "1.0.4",
+			"resolved": "https://registry.npmjs.org/@types/murmurhash-js/-/murmurhash-js-1.0.4.tgz",
+			"integrity": "sha512-lTFERysuLTbtxv/GTcBDV3j3UR1C9WTNiU7rY9QvEUn1G60q7HRXj6c+eFGo0ymMFOlb6kqZsO2WYyzc15oGHA==",
+			"dev": true
+		},
 		"node_modules/@types/needle": {
 			"version": "3.2.0",
 			"resolved": "https://registry.npmjs.org/@types/needle/-/needle-3.2.0.tgz",
@@ -5780,6 +5788,11 @@
 				"node": ">=8"
 			}
 		},
+		"node_modules/murmurhash-js": {
+			"version": "1.0.0",
+			"resolved": "https://registry.npmjs.org/murmurhash-js/-/murmurhash-js-1.0.0.tgz",
+			"integrity": "sha512-TvmkNhkv8yct0SVBSy+o8wYzXjE4Zz3PCesbfs8HiCXXdcTuocApFv11UWlNFWKYsP2okqrhb7JNlSm9InBhIw=="
+		},
 		"node_modules/mz": {
 			"version": "2.7.0",
 			"resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz",
@@ -9755,6 +9768,12 @@
 				"@types/express": "*"
 			}
 		},
+		"@types/murmurhash-js": {
+			"version": "1.0.4",
+			"resolved": "https://registry.npmjs.org/@types/murmurhash-js/-/murmurhash-js-1.0.4.tgz",
+			"integrity": "sha512-lTFERysuLTbtxv/GTcBDV3j3UR1C9WTNiU7rY9QvEUn1G60q7HRXj6c+eFGo0ymMFOlb6kqZsO2WYyzc15oGHA==",
+			"dev": true
+		},
 		"@types/needle": {
 			"version": "3.2.0",
 			"resolved": "https://registry.npmjs.org/@types/needle/-/needle-3.2.0.tgz",
@@ -12602,6 +12621,11 @@
 				"minimatch": "^3.0.4"
 			}
 		},
+		"murmurhash-js": {
+			"version": "1.0.0",
+			"resolved": "https://registry.npmjs.org/murmurhash-js/-/murmurhash-js-1.0.0.tgz",
+			"integrity": "sha512-TvmkNhkv8yct0SVBSy+o8wYzXjE4Zz3PCesbfs8HiCXXdcTuocApFv11UWlNFWKYsP2okqrhb7JNlSm9InBhIw=="
+		},
 		"mz": {
 			"version": "2.7.0",
 			"resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz",
diff --git a/package.json b/package.json
index a6017c8a..3e963b57 100644
--- a/package.json
+++ b/package.json
@@ -49,6 +49,7 @@
 		"@types/jsonwebtoken": "^8.5.9",
 		"@types/morgan": "^1.9.3",
 		"@types/multer": "^1.4.7",
+		"@types/murmurhash-js": "^1.0.4",
 		"@types/node": "^18.7.20",
 		"@types/node-fetch": "^2.6.2",
 		"@types/node-os-utils": "^1.3.0",
@@ -94,6 +95,7 @@
 		"module-alias": "^2.2.2",
 		"morgan": "^1.10.0",
 		"multer": "^1.4.5-lts.1",
+		"murmurhash-js": "^1.0.0",
 		"node-2fa": "^2.0.3",
 		"node-fetch": "^2.6.7",
 		"node-os-utils": "^1.3.7",
diff --git a/src/gateway/opcodes/LazyRequest.ts b/src/gateway/opcodes/LazyRequest.ts
index cde91a75..77e1a25a 100644
--- a/src/gateway/opcodes/LazyRequest.ts
+++ b/src/gateway/opcodes/LazyRequest.ts
@@ -27,6 +27,8 @@ import {
 	User,
 	Presence,
 	partition,
+	Channel,
+	Permissions,
 } from "@spacebar/util";
 import {
 	WebSocket,
@@ -35,6 +37,7 @@ import {
 	OPCODES,
 	Send,
 } from "@spacebar/gateway";
+import murmur from "murmurhash-js/murmurhash3_gc";
 import { check } from "./instanceOf";
 
 // TODO: only show roles/members that have access to this channel
@@ -271,6 +274,28 @@ export async function onLazyRequest(this: WebSocket, { d }: Payload) {
 		ranges.map((x) => getMembers(guild_id, x as [number, number])),
 	);
 
+	let list_id = "everyone";
+
+	const channel = await Channel.findOneOrFail({
+		where: { id: channel_id },
+	});
+	if (channel.permission_overwrites) {
+		const perms: string[] = [];
+
+		channel.permission_overwrites.forEach((overwrite) => {
+			const { id, allow, deny } = overwrite;
+
+			if (allow.toBigInt() & Permissions.FLAGS.VIEW_CHANNEL)
+				perms.push(`allow:${id}`);
+			else if (deny.toBigInt() & Permissions.FLAGS.VIEW_CHANNEL)
+				perms.push(`deny:${id}`);
+		});
+
+		if (perms.length > 0) {
+			list_id = murmur(perms.sort().join(",")).toString();
+		}
+	}
+
 	// TODO: unsubscribe member_events that are not in op.members
 
 	ops.forEach((op) => {
@@ -299,7 +324,7 @@ export async function onLazyRequest(this: WebSocket, { d }: Payload) {
 				member_count -
 				(groups.find((x) => x.id == "offline")?.count ?? 0),
 			member_count,
-			id: "everyone",
+			id: list_id,
 			guild_id,
 			groups,
 		},