1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-10 20:52:42 +01:00
This commit is contained in:
Flam3rboy 2021-09-03 15:27:00 +02:00
parent a446837679
commit d5fcb7f971
8 changed files with 34 additions and 28 deletions

View File

@ -37,12 +37,22 @@ router.patch("/", check(GuildUpdateSchema), async (req: Request, res: Response)
if (body.banner) body.banner = await handleFile(`/banners/${guild_id}`, body.banner);
if (body.splash) body.splash = await handleFile(`/splashes/${guild_id}`, body.splash);
const guild = await Guild.findOneOrFail({ id: guild_id });
var guild = await Guild.findOneOrFail({
where: { id: guild_id },
relations: ["emojis", "roles", "stickers"]
});
// TODO: check if body ids are valid
guild.assign(body);
await Promise.all([guild.save(), emitEvent({ event: "GUILD_UPDATE", data: guild, guild_id } as GuildUpdateEvent)]);
const data = guild.toJSON();
// TODO: guild hashes
// TODO: fix vanity_url_code, template_id
delete data.vanity_url_code;
delete data.template_id;
return res.json(guild);
await Promise.all([guild.save(), emitEvent({ event: "GUILD_UPDATE", data, guild_id } as GuildUpdateEvent)]);
return res.json(data);
});
export default router;

View File

@ -40,6 +40,8 @@ router.post("/", check(GuildCreateSchema), async (req: Request, res: Response) =
premium_tier: 0,
system_channel_flags: 0,
unavailable: false,
nsfw: false,
nsfw_level: 0,
verification_level: 0,
welcome_screen: {
enabled: false,

View File

@ -33,7 +33,7 @@ export const GuildUpdateSchema = {
$icon: String,
$verification_level: Number,
$default_message_notifications: Number,
$system_channel_flags: String,
$system_channel_flags: Number,
$system_channel_id: String,
$explicit_content_filter: Number,
$public_updates_channel_id: String,

View File

@ -138,12 +138,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
// @ts-ignore
guilds: guilds.map((x) => {
// @ts-ignore
x.guild_hashes = {
channels: { omitted: false, hash: "y4PV2fZ0gmo" },
metadata: { omitted: false, hash: "bs1/ckvud3Y" },
roles: { omitted: false, hash: "SxA+c5CaYpo" },
version: 1,
};
x.guild_hashes = {};
return x;
}),
guild_experiments: [], // TODO

View File

@ -17,6 +17,8 @@ import { Webhook } from "./Webhook";
// TODO: stage_instances
// TODO: threads
export const PublicGuildRelations = ["channels", "emojis", "members", "roles", "stickers", "voice_states"];
@Entity("guilds")
export class Guild extends BaseClass {
@Column({ nullable: true })
@ -91,9 +93,9 @@ export class Guild extends BaseClass {
@Column({ nullable: true })
@RelationId((guild: Guild) => guild.template)
template_id: string;
template_id?: string;
@JoinColumn({ name: "template_id" })
@JoinColumn({ name: "template_id", referencedColumnName: "id" })
@ManyToOne(() => Template)
template: Template;
@ -127,7 +129,7 @@ export class Guild extends BaseClass {
@RelationId((guild: Guild) => guild.owner)
owner_id: string;
@JoinColumn([{ name: "owner_id", referencedColumnName: "id" }])
@JoinColumn({ name: "owner_id", referencedColumnName: "id" })
@ManyToOne(() => User)
owner: User;
@ -209,4 +211,10 @@ export class Guild extends BaseClass {
@Column({ nullable: true })
widget_enabled?: boolean;
@Column({ nullable: true })
nsfw_level?: number;
@Column({ nullable: true })
nsfw?: boolean;
}

View File

@ -26,6 +26,7 @@ import { HTTPError } from "lambert-server";
import { Role } from "./Role";
import { Snowflake } from "../util/Snowflake";
import { BaseClassWithoutId } from "./BaseClass";
import { PublicGuildRelations } from ".";
@Entity("members")
@Index(["id", "guild_id"], { unique: true })
@ -209,7 +210,7 @@ export class Member extends BaseClassWithoutId {
where: {
id: guild_id,
},
relations: ["channels", "emojis", "members", "roles", "stickers", "voice_states"],
relations: PublicGuildRelations,
});
if (await Member.count({ id: user.id, guild: { id: guild_id } }))
@ -259,12 +260,7 @@ export class Member extends BaseClassWithoutId {
...guild,
members: [...guild.members, { ...member, user }],
member_count: (guild.member_count || 0) + 1,
guild_hashes: {
channels: { omitted: false, hash: "nkMQJ5nl5Cg" },
metadata: { omitted: false, hash: "+5ybMfcb8iw" },
roles: { omitted: false, hash: "Idhc6P9ktfM" },
version: 1,
},
guild_hashes: {},
guild_scheduled_events: [],
joined_at: member.joined_at,
presences: [],

View File

@ -1,11 +1,11 @@
import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn, RelationId } from "typeorm";
import { Column, Entity, Index, JoinColumn, ManyToOne, PrimaryColumn, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass";
import { Guild } from "./Guild";
import { User } from "./User";
@Entity("templates")
export class Template extends BaseClass {
@PrimaryColumn()
@Column({ unique: true })
code: string;
@Column()

View File

@ -127,12 +127,7 @@ export interface GuildCreateEvent extends Event {
joined_at: Date;
// TODO: add them to guild
guild_scheduled_events: never[];
guild_hashes: {
channels: { omitted: boolean; hash: string };
metadata: { omitted: boolean; hash: string };
roles: { omitted: boolean; hash: string };
version: number;
};
guild_hashes: {};
presences: never[];
stage_instances: never[];
threads: never[];