summary refs log tree commit diff
path: root/gateway
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-31 17:58:28 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-31 17:58:28 +0200
commitadc75ca76b5561d6d4e8d01c5fdd574f8b98363a (patch)
tree81840d8752cb76b8737bb7749af8c04b33ca44a3 /gateway
parentChannel utility methods in entity (diff)
downloadserver-adc75ca76b5561d6d4e8d01c5fdd574f8b98363a.tar.xz
:sparkles: channel recipients
Diffstat (limited to 'gateway')
-rw-r--r--gateway/package-lock.json4
-rw-r--r--gateway/src/listener/listener.ts10
-rw-r--r--gateway/src/opcodes/Identify.ts42
3 files changed, 35 insertions, 21 deletions
diff --git a/gateway/package-lock.json b/gateway/package-lock.json
index 5190b6b0..40606ecd 100644
--- a/gateway/package-lock.json
+++ b/gateway/package-lock.json
@@ -55,7 +55,7 @@
 				"reflect-metadata": "^0.1.13",
 				"sqlite3": "^5.0.2",
 				"typeorm": "^0.2.37",
-				"typescript": "^4.3.5",
+				"typescript": "^4.4.2",
 				"typescript-json-schema": "^0.50.1"
 			},
 			"devDependencies": {
@@ -1949,7 +1949,7 @@
 				"reflect-metadata": "^0.1.13",
 				"sqlite3": "^5.0.2",
 				"typeorm": "^0.2.37",
-				"typescript": "^4.3.5",
+				"typescript": "^4.4.2",
 				"typescript-json-schema": "^0.50.1"
 			}
 		},
diff --git a/gateway/src/listener/listener.ts b/gateway/src/listener/listener.ts
index 8fa96555..75ca1680 100644
--- a/gateway/src/listener/listener.ts
+++ b/gateway/src/listener/listener.ts
@@ -14,7 +14,8 @@ import { Send } from "../util/Send";
 import WebSocket from "../util/WebSocket";
 import "missing-native-js-functions";
 import { Channel as AMQChannel } from "amqplib";
-import { In } from "../../../util/node_modules/typeorm";
+import { In, Like } from "../../../util/node_modules/typeorm";
+import { Recipient } from "../../../util/dist/entities/Recipient";
 
 // TODO: close connection on Invalidated Token
 // TODO: check intent
@@ -28,10 +29,9 @@ export async function setupListener(this: WebSocket) {
 	const members = await Member.find({ where: { id: this.user_id } });
 	const guild_ids = members.map((x) => x.guild_id);
 	const user = await User.findOneOrFail({ id: this.user_id });
-	const channels = await Channel.find({
-		where: [{ recipient_ids: this.user_id }, { guild_id: In(guild_ids) }],
-	});
-	const dm_channels = channels.filter((x) => !x.guild_id);
+	const recipients = await Recipient.find({ where: { id: this.user_id }, relations: ["channel"] });
+	const channels = await Channel.find({ guild_id: In(guild_ids) });
+	const dm_channels = recipients.map((x) => x.channel);
 	const guild_channels = channels.filter((x) => x.guild_id);
 
 	const opts: { acknowledge: boolean; channel?: AMQChannel } = { acknowledge: true };
diff --git a/gateway/src/opcodes/Identify.ts b/gateway/src/opcodes/Identify.ts
index 87008998..958f1b73 100644
--- a/gateway/src/opcodes/Identify.ts
+++ b/gateway/src/opcodes/Identify.ts
@@ -1,12 +1,25 @@
 import { CLOSECODES, Payload, OPCODES } from "../util/Constants";
 import WebSocket from "../util/WebSocket";
-import { Channel, checkToken, Guild, Intents, Member, ReadyEventData, User, EVENTEnum, Config } from "@fosscord/util";
+import {
+	Channel,
+	checkToken,
+	Guild,
+	Intents,
+	Member,
+	ReadyEventData,
+	User,
+	EVENTEnum,
+	Config,
+	dbConnection,
+} from "@fosscord/util";
 import { setupListener } from "../listener/listener";
 import { IdentifySchema } from "../schema/Identify";
 import { Send } from "../util/Send";
 // import experiments from "./experiments.json";
 const experiments: any = [];
 import { check } from "./instanceOf";
+import { Like } from "../../../util/node_modules/typeorm";
+import { Recipient } from "../../../util/dist/entities/Recipient";
 
 // TODO: bot sharding
 // TODO: check priviliged intents
@@ -42,17 +55,21 @@ export async function onIdentify(this: WebSocket, data: Payload) {
 		}
 	}
 
-	const members = await Member.find({ where: { id: this.user_id }, relations: ["guild"] });
+	const members = await Member.find({
+		where: { id: this.user_id },
+		relations: ["guild", "guild.channels", "guild.emojis", "guild.roles", "guild.stickers", "user", "roles"],
+	});
 	const merged_members = members.map((x: any) => {
-		const y = { ...x, user_id: x.id };
-		delete y.settings;
-		delete y.id;
-		return [y];
+		return [x];
 	}) as Member[][];
-	const guilds = members.map((x) => x.guild);
+	const guilds = members.map((x) => ({ ...x.guild, joined_at: x.joined_at }));
 	const user_guild_settings_entries = members.map((x) => x.settings);
 
-	const channels = await Channel.find({ where: { recipient_ids: this.user_id } });
+	const recipients = await Recipient.find({
+		where: { id: this.user_id },
+		relations: ["channel", "channel.recipients"],
+	});
+	const channels = recipients.map((x) => x.channel);
 	const user = await User.findOneOrFail({ id: this.user_id });
 	if (!user) return this.close(CLOSECODES.Authentication_failed);
 
@@ -63,6 +80,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
 		public_flags: user.public_flags,
 		avatar: user.avatar,
 		bot: user.bot,
+		bio: user.bio,
 	};
 
 	const privateUser = {
@@ -116,11 +134,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
 			partial: false, // TODO partial
 			version: 642,
 		},
-		// @ts-ignore
-		private_channels: channels.map((x): ChannelDocument => {
-			delete x.recipients;
-			return x;
-		}),
+		private_channels: channels,
 		session_id: "", // TODO
 		analytics_token: "", // TODO
 		connected_accounts: [], // TODO
@@ -134,7 +148,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
 		// @ts-ignore
 		experiments: experiments, // TODO
 		guild_join_requests: [], // TODO what is this?
-		users: [public_user, ...channels.map((x: any) => x.recipients).flat()].unique(), // TODO
+		users: [public_user].unique(), // TODO
 		merged_members: merged_members,
 		// shard // TODO: only for bots sharding
 		// application // TODO for applications