summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlTech98 <altech123159@gmail.com>2021-09-18 10:44:25 +0200
committerAlTech98 <altech123159@gmail.com>2021-09-18 10:44:25 +0200
commit97e0c8709bdda98d92b97f1085bda505880f8068 (patch)
treea0259fcb1a17580f750b6cd1f09764ae4b8825da
parentMerge branch 'fosscord:master' into fix-dm (diff)
downloadserver-97e0c8709bdda98d92b97f1085bda505880f8068.tar.xz
Fix gateway not listening for new channels events
-rw-r--r--gateway/src/listener/listener.ts11
-rw-r--r--util/src/services/ChannelService.ts15
-rw-r--r--util/src/util/Event.ts1
3 files changed, 9 insertions, 18 deletions
diff --git a/gateway/src/listener/listener.ts b/gateway/src/listener/listener.ts
index 16803639..35841312 100644
--- a/gateway/src/listener/listener.ts
+++ b/gateway/src/listener/listener.ts
@@ -116,7 +116,7 @@ async function consume(this: WebSocket, opts: EventOpts) {
 					.has("VIEW_CHANNEL")
 			)
 				return;
-			break;
+			//No break needed here, we need to call the listenEvent function below
 		case "GUILD_CREATE":
 			this.events[id] = await listenEvent(id, consumer, listenOpts);
 			break;
@@ -193,16 +193,11 @@ async function consume(this: WebSocket, opts: EventOpts) {
 			break;
 	}
 
-	let aa = {
+	Send(this, {
 		op: OPCODES.Dispatch,
 		t: event,
 		d: data,
 		s: this.sequence++,
-	}
-
-	//TODO remove before PR merge
-	console.log(aa)
-
-	Send(this, aa);
+	});
 	opts.acknowledge?.();
 }
diff --git a/util/src/services/ChannelService.ts b/util/src/services/ChannelService.ts
index 8f57a28a..aa021a4a 100644
--- a/util/src/services/ChannelService.ts
+++ b/util/src/services/ChannelService.ts
@@ -84,15 +84,18 @@ export class ChannelService {
 			return
 		}
 
-		let channel_dto = null;
+		await emitEvent({
+			event: "CHANNEL_DELETE",
+			data: await DmChannelDTO.from(channel, [user_id]),
+			user_id: user_id
+		});
 
 		//If the owner leave we make the first recipient in the list the new owner
 		if (channel.owner_id === user_id) {
 			channel.owner_id = channel.recipients!.find(r => r.user_id !== user_id)!.user_id //Is there a criteria to choose the new owner?
-			channel_dto = await DmChannelDTO.from(channel, [user_id])
 			await emitEvent({
 				event: "CHANNEL_UPDATE",
-				data: channel_dto,
+				data: await DmChannelDTO.from(channel, [user_id]),
 				channel_id: channel.id
 			});
 		}
@@ -100,12 +103,6 @@ export class ChannelService {
 		await channel.save()
 
 		await emitEvent({
-			event: "CHANNEL_DELETE",
-			data: channel_dto !== null ? channel_dto : await DmChannelDTO.from(channel, [user_id]),
-			user_id: user_id
-		});
-
-		await emitEvent({
 			event: "CHANNEL_RECIPIENT_REMOVE", data: {
 				channel_id: channel.id,
 				user: await User.findOneOrFail({ where: { id: user_id }, select: PublicUserProjection })
diff --git a/util/src/util/Event.ts b/util/src/util/Event.ts
index ae296df9..765e5fc7 100644
--- a/util/src/util/Event.ts
+++ b/util/src/util/Event.ts
@@ -5,7 +5,6 @@ import { EVENT, Event } from "../interfaces";
 const events = new EventEmitter();
 
 export async function emitEvent(payload: Omit<Event, "created_at">) {
-	console.log(payload) //TODO remove before merge
 	const id = (payload.channel_id || payload.user_id || payload.guild_id) as string;
 	if (!id) return console.error("event doesn't contain any id", payload);