summary refs log tree commit diff
path: root/gateway
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-13 22:57:46 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-13 22:57:46 +0200
commit1f167e11df2535819a9d595f5302438fa52625b5 (patch)
treeffe704051842826603cabd7051e376a2f12aeb15 /gateway
parentMerge branch 'master' of https://github.com/fosscord/fosscord-api (diff)
downloadserver-1f167e11df2535819a9d595f5302438fa52625b5.tar.xz
:construction: fix server bundle
Diffstat (limited to 'gateway')
-rw-r--r--gateway/src/Server.ts2
-rw-r--r--gateway/src/listener/listener.ts13
2 files changed, 9 insertions, 6 deletions
diff --git a/gateway/src/Server.ts b/gateway/src/Server.ts
index c2bc9c47..a50c24a6 100644
--- a/gateway/src/Server.ts
+++ b/gateway/src/Server.ts
@@ -23,6 +23,8 @@ export class Server {
 			});
 
 		this.server.on("upgrade", (request, socket, head) => {
+			console.log("socket requests upgrade", request.url);
+			// @ts-ignore
 			this.ws.handleUpgrade(request, socket, head, (socket) => {
 				this.ws.emit("connection", socket, request);
 			});
diff --git a/gateway/src/listener/listener.ts b/gateway/src/listener/listener.ts
index 708bfe5c..51082586 100644
--- a/gateway/src/listener/listener.ts
+++ b/gateway/src/listener/listener.ts
@@ -58,13 +58,14 @@ export async function setupListener(this: WebSocket) {
 				this.permissions[guild] = x;
 				this.listeners;
 				this.events[guild] = await listenEvent(guild, consumer, opts);
-				for (const channel of guild_channels) {
+
+				for (const channel of guild_channels.filter((c) => c.guild_id === guild)) {
 					if (x.overwriteChannel(channel.permission_overwrites).has("VIEW_CHANNEL")) {
 						this.events[channel.id] = await listenEvent(channel.id, consumer, opts);
 					}
 				}
 			})
-			.catch((e) => {});
+			.catch((e) => console.log("couldn't get permission for guild " + guild, e));
 	}
 
 	this.once("close", () => {
@@ -74,14 +75,14 @@ export async function setupListener(this: WebSocket) {
 }
 
 // TODO: only subscribe for events that are in the connection intents
-function consume(this: WebSocket, opts: EventOpts) {
+async function consume(this: WebSocket, opts: EventOpts) {
 	const { data, event } = opts;
 	const id = data.id as string;
 	const permission = this.permissions[id] || new Permissions("ADMINISTRATOR"); // default permission for dm
 
 	const consumer = consume.bind(this);
 	const listenOpts = opts as ListenEventOpts;
-	console.log("event", event);
+	// console.log("event", event);
 
 	// subscription managment
 	switch (event) {
@@ -94,14 +95,14 @@ function consume(this: WebSocket, opts: EventOpts) {
 			if (!permission.overwriteChannel(data.permission_overwrites).has("VIEW_CHANNEL")) return;
 		// TODO: check if user has permission to channel
 		case "GUILD_CREATE":
-			listenEvent(id, consumer, listenOpts);
+			this.events[id] = await listenEvent(id, consumer, listenOpts);
 			break;
 		case "CHANNEL_UPDATE":
 			const exists = this.events[id];
 			// @ts-ignore
 			if (permission.overwriteChannel(data.permission_overwrites).has("VIEW_CHANNEL")) {
 				if (exists) break;
-				listenEvent(id, consumer, listenOpts);
+				this.events[id] = await listenEvent(id, consumer, listenOpts);
 			} else {
 				if (!exists) return; // return -> do not send channel update events for hidden channels
 				opts.cancel(id);