From c82b71695d16b0ef19d5e976ea7ca47c62ef3345 Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Thu, 28 Sep 2023 16:10:57 +0000 Subject: send Follow request to guild when remote invite code used --- src/util/entities/FederationActivity.ts | 18 +++++++ src/util/entities/Guild.ts | 95 +++++++++++++++++---------------- src/util/entities/index.ts | 1 + 3 files changed, 68 insertions(+), 46 deletions(-) create mode 100644 src/util/entities/FederationActivity.ts (limited to 'src/util/entities') diff --git a/src/util/entities/FederationActivity.ts b/src/util/entities/FederationActivity.ts new file mode 100644 index 00000000..b9a1ac33 --- /dev/null +++ b/src/util/entities/FederationActivity.ts @@ -0,0 +1,18 @@ +import { APActivity } from "activitypub-types"; +import { Column, Entity } from "typeorm"; +import { Config } from ".."; +import { BaseClass } from "./BaseClass"; + +@Entity("federation_activities") +export class FederationActivity extends BaseClass { + @Column({ type: "simple-json" }) + data: APActivity; + + toJSON(): APActivity { + const { host } = Config.get().federation; + return { + id: `https://${host}/federation/activities/${this.id}`, + ...this.data, + }; + } +} diff --git a/src/util/entities/Guild.ts b/src/util/entities/Guild.ts index c50e81e2..a7243eff 100644 --- a/src/util/entities/Guild.ts +++ b/src/util/entities/Guild.ts @@ -17,6 +17,7 @@ */ import { + BeforeInsert, Column, Entity, JoinColumn, @@ -83,8 +84,8 @@ export class Guild extends BaseClass { @ManyToOne(() => Channel) afk_channel?: Channel; - @Column({ nullable: true }) - afk_timeout?: number; + @Column() + afk_timeout: number; // * commented out -> use owner instead // application id of the guild creator if it is bot-created @@ -135,11 +136,11 @@ export class Guild extends BaseClass { @Column({ nullable: true }) max_video_channel_users?: number; - @Column({ nullable: true }) - member_count?: number; + @Column({ default: 0 }) + member_count: number; - @Column({ nullable: true }) - presence_count?: number; // users online + @Column({ nullable: true, type: Number, default: 0 }) + presence_count: number | null; // users online @OneToMany(() => Member, (member: Member) => member.guild, { cascade: true, @@ -211,8 +212,8 @@ export class Guild extends BaseClass { }) webhooks: Webhook[]; - @Column({ nullable: true }) - mfa_level?: number; + @Column({ default: 0 }) + mfa_level: number; @Column() name: string; @@ -225,14 +226,14 @@ export class Guild extends BaseClass { @ManyToOne(() => User) owner?: User; // optional to allow for ownerless guilds - @Column({ nullable: true }) - preferred_locale?: string; + @Column({ nullable: true, type: String, default: "en-US" }) + preferred_locale: string | null; - @Column({ nullable: true }) + @Column({ nullable: true, type: Number, default: 0 }) premium_subscription_count?: number; - @Column() - premium_tier?: number; // crowd premium level + @Column({ default: 0 }) + premium_tier: number; // crowd premium level @Column({ nullable: true }) @RelationId((guild: Guild) => guild.public_updates_channel) @@ -264,17 +265,17 @@ export class Guild extends BaseClass { @ManyToOne(() => Channel) system_channel?: Channel; - @Column({ nullable: true }) + @Column({ default: 4 }) // defaults effect: suppress the setup tips to save performance system_channel_flags?: number; @Column() unavailable: boolean = false; - @Column({ nullable: true }) - verification_level?: number; + @Column({ default: 0 }) + verification_level: number; - @Column({ type: "simple-json" }) - welcome_screen: GuildWelcomeScreen; + @Column({ type: "simple-json", nullable: true }) // TODO: move this to own table + welcome_screen: GuildWelcomeScreen | null; @Column({ nullable: true }) @RelationId((guild: Guild) => guild.widget_channel) @@ -287,8 +288,8 @@ export class Guild extends BaseClass { @Column() widget_enabled: boolean = true; - @Column({ nullable: true }) - nsfw_level?: number; + @Column({ default: 0 }) + nsfw_level: number; @Column() nsfw: boolean = false; @@ -317,32 +318,6 @@ export class Guild extends BaseClass { name: body.name || "Spacebar", icon: await handleFile(`/icons/${guild_id}`, body.icon as string), owner_id: body.owner_id, // TODO: need to figure out a way for ownerless guilds and multiply-owned guilds - presence_count: 0, - member_count: 0, // will automatically be increased by addMember() - mfa_level: 0, - preferred_locale: "en-US", - premium_subscription_count: 0, - premium_tier: 0, - system_channel_flags: 4, // defaults effect: suppress the setup tips to save performance - nsfw_level: 0, - verification_level: 0, - welcome_screen: { - enabled: false, - description: "", - welcome_channels: [], - }, - - afk_timeout: Config.get().defaults.guild.afkTimeout, - default_message_notifications: - Config.get().defaults.guild.defaultMessageNotifications, - explicit_content_filter: - Config.get().defaults.guild.explicitContentFilter, - features: Config.get().guild.defaultFeatures, - max_members: Config.get().limits.guild.maxMembers, - max_presences: Config.get().defaults.guild.maxPresences, - max_video_channel_users: - Config.get().defaults.guild.maxVideoChannelUsers, - region: Config.get().regions.default, }).save(); // we have to create the role _after_ the guild because else we would get a "SQLITE_CONSTRAINT: FOREIGN KEY constraint failed" error @@ -414,4 +389,32 @@ export class Guild extends BaseClass { unavailable: this.unavailable == false ? undefined : true, }; } + + @BeforeInsert() + __set_defaults = () => { + if (!this.afk_timeout) + this.afk_timeout = Config.get().defaults.guild.afkTimeout; + + if (!this.default_message_notifications) + this.default_message_notifications = + Config.get().defaults.guild.defaultMessageNotifications; + + if (!this.explicit_content_filter) + this.explicit_content_filter = + Config.get().defaults.guild.explicitContentFilter; + + if (!this.features) this.features = Config.get().guild.defaultFeatures; + + if (!this.max_members) + this.max_members = Config.get().limits.guild.maxMembers; + + if (!this.max_presences) + this.afk_timeout = Config.get().defaults.guild.maxPresences; + + if (!this.max_video_channel_users) + this.max_video_channel_users = + Config.get().defaults.guild.maxVideoChannelUsers; + + if (!this.region) this.region = Config.get().regions.default; + }; } diff --git a/src/util/entities/index.ts b/src/util/entities/index.ts index 708f2801..a5216d5a 100644 --- a/src/util/entities/index.ts +++ b/src/util/entities/index.ts @@ -31,6 +31,7 @@ export * from "./ConnectionConfigEntity"; export * from "./EmbedCache"; export * from "./Emoji"; export * from "./Encryption"; +export * from "./FederationActivity"; export * from "./FederationKeys"; export * from "./Guild"; export * from "./Invite"; -- cgit 1.4.1