diff --git a/util/src/entities/Guild.ts b/util/src/entities/Guild.ts
index 77a04350..d146e577 100644
--- a/util/src/entities/Guild.ts
+++ b/util/src/entities/Guild.ts
@@ -53,7 +53,7 @@ export class Guild extends BaseClass {
afk_channel?: Channel;
@Column({ nullable: true })
- afk_timeout?: number;
+ afk_timeout?: number = Config.get().defaults.guild.afkTimeout;
// * commented out -> use owner instead
// application id of the guild creator if it is bot-created
@@ -71,7 +71,7 @@ export class Guild extends BaseClass {
banner?: string;
@Column({ nullable: true })
- default_message_notifications?: number;
+ default_message_notifications?: number = Config.get().defaults.guild.defaultMessageNotifications;
@Column({ nullable: true })
description?: string;
@@ -80,7 +80,7 @@ export class Guild extends BaseClass {
discovery_splash?: string;
@Column({ nullable: true })
- explicit_content_filter?: number;
+ explicit_content_filter?: number = Config.get().defaults.guild.explicitContentFilter;
@Column({ type: "simple-array" })
features: string[]; //TODO use enum
@@ -96,19 +96,19 @@ export class Guild extends BaseClass {
large?: boolean;
@Column({ nullable: true })
- max_members?: number; // e.g. default 100.000
+ max_members?: number = Config.get().limits.guild.maxMembers; // e.g. default 100.000
@Column({ nullable: true })
- max_presences?: number;
+ max_presences?: number = Config.get().defaults.guild.maxPresences;
@Column({ nullable: true })
- max_video_channel_users?: number; // ? default: 25, is this max 25 streaming or watching
+ max_video_channel_users?: number = Config.get().defaults.guild.maxVideoChannelUsers; // ? default: 25, is this max 25 streaming or watching
@Column({ nullable: true })
- member_count?: number;
+ member_count?: number = 0;
@Column({ nullable: true })
- presence_count?: number; // users online
+ presence_count?: number = 0; // users online
@OneToMany(() => Member, (member: Member) => member.guild, {
cascade: true,
@@ -278,6 +278,10 @@ export class Guild extends BaseClass {
// only for developer portal
permissions?: number;
+ //new guild settings, 11/08/2022:
+ @Column({ nullable: true })
+ premium_progress_bar_enabled: boolean = false;
+
static async createGuild(body: {
name?: string;
icon?: string | null;
diff --git a/util/src/entities/User.ts b/util/src/entities/User.ts
index a9f00b0d..6edcda97 100644
--- a/util/src/entities/User.ts
+++ b/util/src/entities/User.ts
@@ -1,11 +1,11 @@
-import { Column, Entity, FindOneOptions, FindOptionsSelectByString, JoinColumn, OneToMany } from "typeorm";
+import { Column, Entity, FindOneOptions, FindOptionsSelectByString, JoinColumn, OneToMany, OneToOne } from "typeorm";
import { OrmUtils } from "../util/imports/OrmUtils";
import { BaseClass } from "./BaseClass";
import { BitField } from "../util/BitField";
import { Relationship } from "./Relationship";
import { ConnectedAccount } from "./ConnectedAccount";
import { Config, FieldErrors, Snowflake, trimSpecial } from "..";
-import { Member, Session } from ".";
+import { Member, Session, UserSettings } from ".";
export enum PublicUserEnum {
username,
@@ -83,28 +83,28 @@ export class User extends BaseClass {
phone?: string; // phone number of the user
@Column({ select: false })
- desktop: boolean; // if the user has desktop app installed
+ desktop: boolean = false; // if the user has desktop app installed
@Column({ select: false })
- mobile: boolean; // if the user has mobile app installed
+ mobile: boolean = false; // if the user has mobile app installed
@Column()
- premium: boolean; // if user bought individual premium
+ premium: boolean = Config.get().defaults.user.premium; // if user bought individual premium
@Column()
- premium_type: number; // individual premium level
+ premium_type: number = Config.get().defaults.user.premium_type; // individual premium level
@Column()
- bot: boolean; // if user is bot
+ bot: boolean = false; // if user is bot
@Column()
bio: string; // short description of the user (max 190 chars -> should be configurable)
@Column()
- system: boolean; // shouldn't be used, the api sends this field type true, if the generated message comes from a system generated author
+ system: boolean = false; // shouldn't be used, the api sends this field type true, if the generated message comes from a system generated author
@Column({ select: false })
- nsfw_allowed: boolean; // if the user can do age-restricted actions (NSFW channels/guilds/commands)
+ nsfw_allowed: boolean = true; // if the user can do age-restricted actions (NSFW channels/guilds/commands) // TODO: depending on age
@Column({ select: false })
mfa_enabled: boolean; // if multi factor authentication is enabled
@@ -116,31 +116,31 @@ export class User extends BaseClass {
totp_last_ticket?: string;
@Column()
- created_at: Date; // registration date
+ created_at: Date = new Date(); // registration date
@Column({ nullable: true })
- premium_since: Date; // premium date
+ premium_since: Date = new Date(); // premium date
@Column({ select: false })
- verified: boolean; // if the user is offically verified
+ verified: boolean = Config.get().defaults.user.verified; // if the user is offically verified
@Column()
- disabled: boolean; // if the account is disabled
+ disabled: boolean = false; // if the account is disabled
@Column()
- deleted: boolean; // if the user was deleted
+ deleted: boolean = false; // if the user was deleted
@Column({ nullable: true, select: false })
email?: string; // email of the user
@Column()
- flags: string; // UserFlags
+ flags: string = "0"; // UserFlags // TODO: generate
@Column()
- public_flags: number;
+ public_flags: number = 0;
@Column({ type: "bigint" })
- rights: string; // Rights
+ rights: string = Config.get().register.defaultRights; // Rights
@OneToMany(() => Session, (session: Session) => session.user)
sessions: Session[];
@@ -166,17 +166,28 @@ export class User extends BaseClass {
};
@Column({ type: "simple-array", select: false })
- fingerprints: string[]; // array of fingerprints -> used to prevent multiple accounts
+ fingerprints: string[] = []; // array of fingerprints -> used to prevent multiple accounts
- @Column({ type: "simple-json", select: false })
+
+ @OneToOne(()=> UserSettings, {
+ cascade: true,
+ orphanedRowAction: "delete",
+ eager: false
+ })
+ @JoinColumn()
settings: UserSettings;
// workaround to prevent fossord-unaware clients from deleting settings not used by them
@Column({ type: "simple-json", select: false })
- extended_settings: string;
+ extended_settings: string = "{}";
@Column({ type: "simple-json" })
- notes: { [key: string]: string }; //key is ID of user
+ notes: { [key: string]: string } = {}; //key is ID of user
+
+ async save(): Promise<any> {
+ await this.settings.save();
+ return this.save();
+ }
toPublicUser() {
const user: any = {};
@@ -256,40 +267,20 @@ export class User extends BaseClass {
const language = req?.language === "en" ? "en-US" : req?.language || "en-US";
const user = OrmUtils.mergeDeep(new User(), {
- created_at: new Date(),
+ //required:
username: username,
discriminator,
id: Snowflake.generate(),
- bot: false,
- system: false,
- premium_since: new Date(),
- desktop: false,
- mobile: false,
- premium: true,
- premium_type: 2,
- bio: "",
- mfa_enabled: false,
- totp_secret: "",
- totp_backup_codes: [],
- verified: true,
- disabled: false,
- deleted: false,
email: email,
- rights: Config.get().register.defaultRights, // TODO: grant rights correctly, as 0 actually stands for no rights at all
- nsfw_allowed: true, // TODO: depending on age
- public_flags: "0",
- flags: "0", // TODO: generate
data: {
hash: password,
valid_tokens_since: new Date(),
},
- settings: { ...defaultSettings, locale: language },
- extended_settings: {},
- fingerprints: [],
- notes: {},
+ settings: { ...new UserSettings(), locale: language }
});
await user.save();
+ await user.settings.save();
setImmediate(async () => {
if (Config.get().guild.autoJoin.enabled) {
@@ -303,85 +294,6 @@ export class User extends BaseClass {
}
}
-export const defaultSettings: UserSettings = {
- afk_timeout: 3600,
- allow_accessibility_detection: true,
- animate_emoji: true,
- animate_stickers: 0,
- contact_sync_enabled: false,
- convert_emoticons: false,
- custom_status: null,
- default_guilds_restricted: false,
- detect_platform_accounts: false,
- developer_mode: true,
- disable_games_tab: true,
- enable_tts_command: false,
- explicit_content_filter: 0,
- friend_source_flags: { all: true },
- gateway_connected: false,
- gif_auto_play: true,
- guild_folders: [],
- guild_positions: [],
- inline_attachment_media: true,
- inline_embed_media: true,
- locale: "en-US",
- message_display_compact: false,
- native_phone_integration_enabled: true,
- render_embeds: true,
- render_reactions: true,
- restricted_guilds: [],
- show_current_game: true,
- status: "online",
- stream_notifications_enabled: false,
- theme: "dark",
- timezone_offset: 0, // TODO: timezone from request
-};
-
-export interface UserSettings {
- afk_timeout: number;
- allow_accessibility_detection: boolean;
- animate_emoji: boolean;
- animate_stickers: number;
- contact_sync_enabled: boolean;
- convert_emoticons: boolean;
- custom_status: {
- emoji_id?: string;
- emoji_name?: string;
- expires_at?: number;
- text?: string;
- } | null;
- default_guilds_restricted: boolean;
- detect_platform_accounts: boolean;
- developer_mode: boolean;
- disable_games_tab: boolean;
- enable_tts_command: boolean;
- explicit_content_filter: number;
- friend_source_flags: { all: boolean };
- gateway_connected: boolean;
- gif_auto_play: boolean;
- // every top guild is displayed as a "folder"
- guild_folders: {
- color: number;
- guild_ids: string[];
- id: number;
- name: string;
- }[];
- guild_positions: string[]; // guild ids ordered by position
- inline_attachment_media: boolean;
- inline_embed_media: boolean;
- locale: string; // en_US
- message_display_compact: boolean;
- native_phone_integration_enabled: boolean;
- render_embeds: boolean;
- render_reactions: boolean;
- restricted_guilds: string[];
- show_current_game: boolean;
- status: "online" | "offline" | "dnd" | "idle" | "invisible";
- stream_notifications_enabled: boolean;
- theme: "dark" | "white"; // dark
- timezone_offset: number; // e.g -60
-}
-
export const CUSTOM_USER_FLAG_OFFSET = BigInt(1) << BigInt(32);
export class UserFlags extends BitField {
diff --git a/util/src/entities/UserSettings.ts b/util/src/entities/UserSettings.ts
new file mode 100644
index 00000000..ef6f95af
--- /dev/null
+++ b/util/src/entities/UserSettings.ts
@@ -0,0 +1,119 @@
+import { Column, Entity, JoinColumn } from "typeorm";
+import { BaseClassWithoutId, PrimaryIdColumn } from ".";
+
+@Entity("user_settings")
+export class UserSettings extends BaseClassWithoutId {
+ @PrimaryIdColumn()
+ id: string;
+
+ @Column({ nullable: true })
+ afk_timeout: number = 3600;
+
+ @Column({ nullable: true })
+ allow_accessibility_detection: boolean = true;
+
+ @Column({ nullable: true })
+ animate_emoji: boolean = true;
+
+ @Column({ nullable: true })
+ animate_stickers: number = 0;
+
+ @Column({ nullable: true })
+ contact_sync_enabled: boolean = false;
+
+ @Column({ nullable: true })
+ convert_emoticons: boolean = false;
+
+ @Column({ nullable: true, type: "simple-json" })
+ custom_status: CustomStatus | null = null;
+
+ @Column({ nullable: true })
+ default_guilds_restricted: boolean = false;
+
+ @Column({ nullable: true })
+ detect_platform_accounts: boolean = false;
+
+ @Column({ nullable: true })
+ developer_mode: boolean = true;
+
+ @Column({ nullable: true })
+ disable_games_tab: boolean = true;
+
+ @Column({ nullable: true })
+ enable_tts_command: boolean = false;
+
+ @Column({ nullable: true })
+ explicit_content_filter: number = 0;
+
+ @Column({ nullable: true, type: "simple-json" })
+ friend_source_flags: FriendSourceFlags = { all: true };
+
+ @Column({ nullable: true })
+ gateway_connected: boolean = false;
+
+ @Column({ nullable: true })
+ gif_auto_play: boolean = false;
+
+ @Column({ nullable: true, type: "simple-json" })
+ guild_folders: GuildFolder[] = []; // every top guild is displayed as a "folder"
+
+ @Column({ nullable: true, type: "simple-json" })
+ guild_positions: string[] = []; // guild ids ordered by position
+
+ @Column({ nullable: true })
+ inline_attachment_media: boolean = true;
+
+ @Column({ nullable: true })
+ inline_embed_media: boolean = true;
+
+ @Column({ nullable: true })
+ locale: string = "en-US"; // en_US
+
+ @Column({ nullable: true })
+ message_display_compact: boolean = false;
+
+ @Column({ nullable: true })
+ native_phone_integration_enabled: boolean = true;
+
+ @Column({ nullable: true })
+ render_embeds: boolean = true;
+
+ @Column({ nullable: true })
+ render_reactions: boolean = true;
+
+ @Column({ nullable: true, type: "simple-json" })
+ restricted_guilds: string[] = [];
+
+ @Column({ nullable: true })
+ show_current_game: boolean = true;
+
+ @Column({ nullable: true })
+ status: "online" | "offline" | "dnd" | "idle" | "invisible" = "online";
+
+ @Column({ nullable: true })
+ stream_notifications_enabled: boolean = false;
+
+ @Column({ nullable: true })
+ theme: "dark" | "white" = "dark"; // dark
+
+ @Column({ nullable: true })
+ timezone_offset: number = 0; // e.g -60
+}
+
+interface CustomStatus {
+ emoji_id?: string;
+ emoji_name?: string;
+ expires_at?: number;
+ text?: string;
+}
+
+interface GuildFolder {
+ color: number;
+ guild_ids: string[];
+ id: number;
+ name: string;
+}
+
+interface FriendSourceFlags {
+ all: boolean
+}
\ No newline at end of file
diff --git a/util/src/entities/index.ts b/util/src/entities/index.ts
index c439a4b7..c6f12022 100644
--- a/util/src/entities/index.ts
+++ b/util/src/entities/index.ts
@@ -30,3 +30,4 @@ export * from "./Webhook";
export * from "./ClientRelease";
export * from "./BackupCodes";
export * from "./Note";
+export * from "./UserSettings";
|