summary refs log tree commit diff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/src/entities/Channel.ts5
-rw-r--r--util/src/entities/Config.ts36
-rw-r--r--util/src/entities/Guild.ts6
-rw-r--r--util/src/entities/Message.ts2
-rw-r--r--util/src/entities/User.ts21
-rw-r--r--util/src/interfaces/Event.ts1
-rw-r--r--util/src/migrations/1660678870706-opencordFixes.ts53
-rw-r--r--util/src/migrations/1660689892073-mobileFixes2.ts31
-rw-r--r--util/src/util/Database.ts2
9 files changed, 113 insertions, 44 deletions
diff --git a/util/src/entities/Channel.ts b/util/src/entities/Channel.ts
index 3e8cd5ef..10fa03ff 100644
--- a/util/src/entities/Channel.ts
+++ b/util/src/entities/Channel.ts
@@ -108,8 +108,8 @@ export class Channel extends BaseClass {
 	@Column({ nullable: true })

 	user_limit?: number;

 

-	@Column({ nullable: true })

-	nsfw?: boolean;

+	@Column()

+	nsfw: boolean = false;

 

 	@Column({ nullable: true })

 	rate_limit_per_user?: number;

@@ -291,6 +291,7 @@ export class Channel extends BaseClass {
 					(x) =>

 						new Recipient({ user_id: x, closed: !(type === ChannelType.GROUP_DM || x === creator_user_id) })

 				),

+				nsfw: false,

 			}).save();

 		}

 

diff --git a/util/src/entities/Config.ts b/util/src/entities/Config.ts
index a1fef058..ac1af7f3 100644
--- a/util/src/entities/Config.ts
+++ b/util/src/entities/Config.ts
@@ -444,38 +444,4 @@ export const DefaultConfigOptions: ConfigValue = {
 		traceSampleRate: 1.0,
 		environment: hostname()
 	}
-};
-
-
-console.log((
-	Rights.FLAGS.MANAGE_GUILDS +
-	Rights.FLAGS.MANAGE_MESSAGES +
-	Rights.FLAGS.MANAGE_TICKETS +
-	Rights.FLAGS.MANAGE_USERS +
-	Rights.FLAGS.CREATE_CHANNELS +
-	Rights.FLAGS.CREATE_DMS +
-	Rights.FLAGS.CREATE_DM_GROUPS +
-	Rights.FLAGS.CREATE_GUILDS +
-	Rights.FLAGS.CREATE_INVITES +
-	Rights.FLAGS.CREATE_ROLES +
-	Rights.FLAGS.CREATE_TEMPLATES +
-	Rights.FLAGS.CREATE_WEBHOOKS +
-	Rights.FLAGS.JOIN_GUILDS +
-	Rights.FLAGS.PIN_MESSAGES +
-	Rights.FLAGS.SELF_ADD_REACTIONS +
-	Rights.FLAGS.SELF_DELETE_MESSAGES +
-	Rights.FLAGS.SELF_EDIT_MESSAGES +
-	Rights.FLAGS.SELF_EDIT_NAME +
-	Rights.FLAGS.SEND_MESSAGES +
-	Rights.FLAGS.USE_ACTIVITIES +
-	Rights.FLAGS.USE_VIDEO +
-	Rights.FLAGS.USE_VOICE +
-	Rights.FLAGS.INVITE_USERS +
-	Rights.FLAGS.SELF_DELETE_DISABLE +
-	Rights.FLAGS.DEBTABLE +
-	Rights.FLAGS.KICK_BAN_MEMBERS +
-	Rights.FLAGS.SELF_LEAVE_GROUPS +
-	Rights.FLAGS.SELF_ADD_DISCOVERABLE +
-	Rights.FLAGS.USE_ACHIEVEMENTS +
-	Rights.FLAGS.USE_MASS_INVITES
-).toString())
\ No newline at end of file
+};
\ No newline at end of file
diff --git a/util/src/entities/Guild.ts b/util/src/entities/Guild.ts
index a5b732e8..143cb542 100644
--- a/util/src/entities/Guild.ts
+++ b/util/src/entities/Guild.ts
@@ -267,8 +267,8 @@ export class Guild extends BaseClass {
 	@Column({ nullable: true })
 	nsfw_level?: number;
 
-	@Column({ nullable: true })
-	nsfw?: boolean;
+	@Column()
+	nsfw: boolean;
 	
 	// TODO: nested guilds
 	@Column({ nullable: true })
@@ -335,7 +335,7 @@ export class Guild extends BaseClass {
 			unicode_emoji: null
 		}).save();
 
-		if (!body.channels || !body.channels.length) body.channels = [{ id: "01", type: 0, name: "general" }];
+		if (!body.channels || !body.channels.length) body.channels = [{ id: "01", type: 0, name: "general", nsfw: false }];
 
 		const ids = new Map();
 
diff --git a/util/src/entities/Message.ts b/util/src/entities/Message.ts
index 013e92a9..83607ed4 100644
--- a/util/src/entities/Message.ts
+++ b/util/src/entities/Message.ts
@@ -122,7 +122,7 @@ export class Message extends BaseClass {
 	timestamp: Date;
 
 	@Column({ nullable: true })
-	edited_timestamp?: Date;
+	edited_timestamp: Date;
 
 	@Column({ nullable: true })
 	tts?: boolean;
diff --git a/util/src/entities/User.ts b/util/src/entities/User.ts
index a8f7f0c3..cac2784a 100644
--- a/util/src/entities/User.ts
+++ b/util/src/entities/User.ts
@@ -30,6 +30,8 @@ export enum PrivateUserEnum {
 	nsfw_allowed,
 	premium,
 	premium_type,
+	purchased_flags,
+	premium_usage_flags,
 	disabled,
 	settings,
 	// locale
@@ -53,8 +55,6 @@ export interface UserPrivate extends Pick<User, PrivateUserKeys> {
 	locale: string;
 }
 
-// TODO: add purchased_flags, premium_usage_flags
-
 @Entity("users")
 export class User extends BaseClass {
 	@Column()
@@ -139,6 +139,12 @@ export class User extends BaseClass {
 	@Column()
 	public_flags: number;
 
+	@Column()
+	purchased_flags: number;
+
+	@Column()
+	premium_usage_flags: number;
+
 	@Column({ type: "bigint" })
 	rights: string; // Rights
 
@@ -281,6 +287,8 @@ export class User extends BaseClass {
 				valid_tokens_since: new Date(),
 			},
 			settings: { ...defaultSettings, locale: language },
+			purchased_flags: 5, // TODO: idk what the values for this are
+			premium_usage_flags: 2,  // TODO: idk what the values for this are
 			extended_settings: {},
 			fingerprints: [],
 			notes: {},
@@ -332,6 +340,11 @@ export const defaultSettings: UserSettings = {
 	stream_notifications_enabled: false,
 	theme: "dark",
 	timezone_offset: 0, // TODO: timezone from request
+
+	banner_color: null,
+	friend_discovery_flags: 0,
+	view_nsfw_guilds: true,
+	passwordless: false,
 };
 
 export interface UserSettings {
@@ -377,6 +390,10 @@ export interface UserSettings {
 	stream_notifications_enabled: boolean;
 	theme: "dark" | "white"; // dark
 	timezone_offset: number; // e.g -60
+	banner_color: string | null;
+	friend_discovery_flags: number;
+	view_nsfw_guilds: boolean;
+	passwordless: boolean;
 }
 
 export const CUSTOM_USER_FLAG_OFFSET = BigInt(1) << BigInt(32);
diff --git a/util/src/interfaces/Event.ts b/util/src/interfaces/Event.ts
index 416082ed..59f995db 100644
--- a/util/src/interfaces/Event.ts
+++ b/util/src/interfaces/Event.ts
@@ -98,6 +98,7 @@ export interface ReadyEventData {
 	merged_members?: PublicMember[][];
 	// probably all users who the user is in contact with
 	users?: PublicUser[];
+	sessions: any[];
 }
 
 export interface ReadyEvent extends Event {
diff --git a/util/src/migrations/1660678870706-opencordFixes.ts b/util/src/migrations/1660678870706-opencordFixes.ts
new file mode 100644
index 00000000..1f10c212
--- /dev/null
+++ b/util/src/migrations/1660678870706-opencordFixes.ts
@@ -0,0 +1,53 @@
+import { MigrationInterface, QueryRunner } from "typeorm";
+
+export class opencordFixes1660678870706 implements MigrationInterface {
+    name = 'opencordFixes1660678870706'
+
+    public async up(queryRunner: QueryRunner): Promise<void> {
+        await queryRunner.query(`
+            ALTER TABLE \`users\`
+            ADD \`purchased_flags\` int NOT NULL
+        `);
+        await queryRunner.query(`
+            ALTER TABLE \`users\`
+            ADD \`premium_usage_flags\` int NOT NULL
+        `);
+        await queryRunner.query(`
+            ALTER TABLE \`user_settings\`
+            ADD \`friend_discovery_flags\` int NOT NULL
+        `);
+        await queryRunner.query(`
+            ALTER TABLE \`user_settings\`
+            ADD \`view_nsfw_guilds\` tinyint NOT NULL
+        `);
+        await queryRunner.query(`
+            ALTER TABLE \`user_settings\`
+            ADD \`passwordless\` tinyint NOT NULL
+        `);
+        await queryRunner.query(`
+            ALTER TABLE \`users\` CHANGE \`mfa_enabled\` \`mfa_enabled\` tinyint NOT NULL
+        `);
+    }
+
+    public async down(queryRunner: QueryRunner): Promise<void> {
+        await queryRunner.query(`
+            ALTER TABLE \`users\` CHANGE \`mfa_enabled\` \`mfa_enabled\` tinyint NULL
+        `);
+        await queryRunner.query(`
+            ALTER TABLE \`user_settings\` DROP COLUMN \`passwordless\`
+        `);
+        await queryRunner.query(`
+            ALTER TABLE \`user_settings\` DROP COLUMN \`view_nsfw_guilds\`
+        `);
+        await queryRunner.query(`
+            ALTER TABLE \`user_settings\` DROP COLUMN \`friend_discovery_flags\`
+        `);
+        await queryRunner.query(`
+            ALTER TABLE \`users\` DROP COLUMN \`premium_usage_flags\`
+        `);
+        await queryRunner.query(`
+            ALTER TABLE \`users\` DROP COLUMN \`purchased_flags\`
+        `);
+    }
+
+}
\ No newline at end of file
diff --git a/util/src/migrations/1660689892073-mobileFixes2.ts b/util/src/migrations/1660689892073-mobileFixes2.ts
new file mode 100644
index 00000000..34328966
--- /dev/null
+++ b/util/src/migrations/1660689892073-mobileFixes2.ts
@@ -0,0 +1,31 @@
+import { MigrationInterface, QueryRunner } from "typeorm";
+
+export class mobileFixes21660689892073 implements MigrationInterface {
+    name = 'mobileFixes21660689892073'
+
+    public async up(queryRunner: QueryRunner): Promise<void> {
+        await queryRunner.query(`
+            ALTER TABLE \`user_settings\`
+            ADD \`banner_color\` varchar(255) NULL
+        `);
+        await queryRunner.query(`
+            ALTER TABLE \`channels\` CHANGE \`nsfw\` \`nsfw\` tinyint NOT NULL
+        `);
+        await queryRunner.query(`
+            ALTER TABLE \`guilds\` CHANGE \`nsfw\` \`nsfw\` tinyint NOT NULL
+        `);
+    }
+
+    public async down(queryRunner: QueryRunner): Promise<void> {
+        await queryRunner.query(`
+            ALTER TABLE \`guilds\` CHANGE \`nsfw\` \`nsfw\` tinyint NULL
+        `);
+        await queryRunner.query(`
+            ALTER TABLE \`channels\` CHANGE \`nsfw\` \`nsfw\` tinyint NULL
+        `);
+        await queryRunner.query(`
+            ALTER TABLE \`user_settings\` DROP COLUMN \`banner_color\`
+        `);
+    }
+
+}
\ No newline at end of file
diff --git a/util/src/util/Database.ts b/util/src/util/Database.ts
index 9ab5d14c..2973e114 100644
--- a/util/src/util/Database.ts
+++ b/util/src/util/Database.ts
@@ -29,7 +29,7 @@ export function initDatabase(): Promise<Connection> {
 		url: isSqlite ? undefined : dbConnectionString,
 		database: isSqlite ? dbConnectionString : undefined,
 		// @ts-ignore
-		entities: Object.values(Models).filter((x) => x.constructor.name !== "Object" && x.name),
+		entities: Object.values(Models).filter((x) => x?.constructor?.name !== "Object" && x?.name),
 		synchronize: type !== "mongodb",
 		logging: false,
 		cache: {