summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-06-11 17:55:59 +1000
committerGitHub <noreply@github.com>2023-06-11 17:55:59 +1000
commit9a227e35faabd20cb21e23a341ea646d33ca485e (patch)
tree9aef7c4c38c002c7d6679186bff30634484e00be /src
parentFix docs for /users/:id/profile (diff)
parentfeat: implement member list id generation (diff)
downloadserver-9a227e35faabd20cb21e23a341ea646d33ca485e.tar.xz
Merge pull request #1068 from V3L0C1T13S/feat/gen_memberlist_id
Implement member list ids
Diffstat (limited to 'src')
-rw-r--r--src/gateway/opcodes/LazyRequest.ts27
1 files changed, 26 insertions, 1 deletions
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,
 		},