mirror of
https://github.com/spacebarchat/server.git
synced 2026-04-29 23:25:47 +00:00
fix(util): util imports
This commit is contained in:
committed by
TheArcaneBrony
parent
3a5ca274da
commit
6765bfafa7
@@ -1,9 +1,9 @@
|
||||
import { Column, Entity, JoinColumn, ManyToOne, OneToMany, RelationId} from "typeorm";
|
||||
import { OrmUtils } from "@fosscord/util";
|
||||
import { Column, Entity, JoinColumn, ManyToOne, OneToMany, RelationId } from "typeorm";
|
||||
import { OrmUtils } from "typeorm/util/OrmUtils";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { Guild } from "./Guild";
|
||||
import { PublicUserProjection, User } from "./User";
|
||||
import { HTTPError } from "..";
|
||||
import { HTTPError } from "../util/imports/HTTPError";
|
||||
import { containsAll, emitEvent, getPermission, Snowflake, trimSpecial, InvisibleCharacters } from "../util";
|
||||
import { ChannelCreateEvent, ChannelRecipientRemoveEvent } from "../interfaces";
|
||||
import { Recipient } from "./Recipient";
|
||||
@@ -35,7 +35,7 @@ export enum ChannelType {
|
||||
KANBAN = 34, // confluence like kanban board
|
||||
VOICELESS_WHITEBOARD = 35, // whiteboard but without voice (whiteboard + voice is the same as stage)
|
||||
CUSTOM_START = 64, // start custom channel types from here
|
||||
UNHANDLED = 255 // unhandled unowned pass-through channel type
|
||||
UNHANDLED = 255, // unhandled unowned pass-through channel type
|
||||
}
|
||||
|
||||
@Entity("channels")
|
||||
@@ -150,7 +150,7 @@ export class Channel extends BaseClass {
|
||||
orphanedRowAction: "delete",
|
||||
})
|
||||
webhooks?: Webhook[];
|
||||
|
||||
|
||||
// TODO: DM channel
|
||||
static async createChannel(
|
||||
channel: Partial<Channel>,
|
||||
@@ -177,16 +177,14 @@ export class Channel extends BaseClass {
|
||||
throw new HTTPError("Channel name cannot include invalid characters", 403);
|
||||
|
||||
if (channel.name.match(/\-\-+/g))
|
||||
throw new HTTPError("Channel name cannot include multiple adjacent dashes.", 403)
|
||||
throw new HTTPError("Channel name cannot include multiple adjacent dashes.", 403);
|
||||
|
||||
if (channel.name.charAt(0) === "-" ||
|
||||
channel.name.charAt(channel.name.length - 1) === "-")
|
||||
throw new HTTPError("Channel name cannot start/end with dash.", 403)
|
||||
if (channel.name.charAt(0) === "-" || channel.name.charAt(channel.name.length - 1) === "-")
|
||||
throw new HTTPError("Channel name cannot start/end with dash.", 403);
|
||||
}
|
||||
|
||||
if (!guild.features.includes("ALLOW_UNNAMED_CHANNELS")) {
|
||||
if (!channel.name)
|
||||
throw new HTTPError("Channel name cannot be empty.", 403);
|
||||
if (!channel.name) throw new HTTPError("Channel name cannot be empty.", 403);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,13 +221,13 @@ export class Channel extends BaseClass {
|
||||
};
|
||||
|
||||
await Promise.all([
|
||||
OrmUtils.mergeDeep(new Channel(),channel).save(),
|
||||
OrmUtils.mergeDeep(new Channel(), channel).save(),
|
||||
!opts?.skipEventEmit
|
||||
? emitEvent({
|
||||
event: "CHANNEL_CREATE",
|
||||
data: channel,
|
||||
guild_id: channel.guild_id,
|
||||
} as ChannelCreateEvent)
|
||||
event: "CHANNEL_CREATE",
|
||||
data: channel,
|
||||
guild_id: channel.guild_id,
|
||||
} as ChannelCreateEvent)
|
||||
: Promise.resolve(),
|
||||
]);
|
||||
|
||||
@@ -274,17 +272,21 @@ export class Channel extends BaseClass {
|
||||
if (channel == null) {
|
||||
name = trimSpecial(name);
|
||||
|
||||
channel = await (OrmUtils.mergeDeep(new Channel(), {
|
||||
name,
|
||||
type,
|
||||
owner_id: type === ChannelType.DM ? undefined : null, // 1:1 DMs are ownerless in fosscord-server
|
||||
created_at: new Date(),
|
||||
last_message_id: null,
|
||||
recipients: channelRecipients.map(
|
||||
(x) =>
|
||||
OrmUtils.mergeDeep(new Recipient(), { user_id: x, closed: !(type === ChannelType.GROUP_DM || x === creator_user_id) })
|
||||
),
|
||||
}) as Channel).save();
|
||||
channel = await (
|
||||
OrmUtils.mergeDeep(new Channel(), {
|
||||
name,
|
||||
type,
|
||||
owner_id: type === ChannelType.DM ? undefined : null, // 1:1 DMs are ownerless in fosscord-server
|
||||
created_at: new Date(),
|
||||
last_message_id: null,
|
||||
recipients: channelRecipients.map((x) =>
|
||||
OrmUtils.mergeDeep(new Recipient(), {
|
||||
user_id: x,
|
||||
closed: !(type === ChannelType.GROUP_DM || x === creator_user_id),
|
||||
})
|
||||
),
|
||||
}) as Channel
|
||||
).save();
|
||||
}
|
||||
|
||||
const channel_dto = await DmChannelDTO.from(channel);
|
||||
@@ -301,7 +303,7 @@ export class Channel extends BaseClass {
|
||||
await emitEvent({ event: "CHANNEL_CREATE", data: channel_dto, user_id: creator_user_id });
|
||||
}
|
||||
|
||||
if (recipients.length === 1) return channel_dto;
|
||||
if (recipients.length === 1) return channel_dto;
|
||||
else return channel_dto.excludedRecipients([creator_user_id]);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Column, Entity, JoinColumn, ManyToMany, ManyToOne, OneToMany, OneToOne, RelationId} from "typeorm";
|
||||
import { OrmUtils } from "@fosscord/util";
|
||||
import { Column, Entity, JoinColumn, ManyToMany, ManyToOne, OneToMany, OneToOne, RelationId } from "typeorm";
|
||||
import { OrmUtils } from "typeorm/util/OrmUtils";
|
||||
import { Config, handleFile, Snowflake } from "..";
|
||||
import { Ban } from "./Ban";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
@@ -270,7 +270,7 @@ export class Guild extends BaseClass {
|
||||
|
||||
@Column({ nullable: true })
|
||||
nsfw?: boolean;
|
||||
|
||||
|
||||
// TODO: nested guilds
|
||||
@Column({ nullable: true })
|
||||
parent?: string;
|
||||
@@ -286,7 +286,7 @@ export class Guild extends BaseClass {
|
||||
}) {
|
||||
const guild_id = Snowflake.generate();
|
||||
|
||||
const guild: Guild = OrmUtils.mergeDeep(new Guild(),{
|
||||
const guild: Guild = OrmUtils.mergeDeep(new Guild(), {
|
||||
name: body.name || "Fosscord",
|
||||
icon: await handleFile(`/icons/${guild_id}`, body.icon as string),
|
||||
region: Config.get().regions.default,
|
||||
@@ -334,7 +334,7 @@ export class Guild extends BaseClass {
|
||||
permissions: String("2251804225"),
|
||||
position: 0,
|
||||
icon: null,
|
||||
unicode_emoji: null
|
||||
unicode_emoji: null,
|
||||
});
|
||||
await role.save();
|
||||
|
||||
|
||||
@@ -20,12 +20,12 @@ import {
|
||||
GuildMemberRemoveEvent,
|
||||
GuildMemberUpdateEvent,
|
||||
} from "../interfaces";
|
||||
import { HTTPError } from "..";
|
||||
import { HTTPError } from "../util/imports/HTTPError";
|
||||
import { Role } from "./Role";
|
||||
import { BaseClassWithoutId } from "./BaseClass";
|
||||
import { Ban, PublicGuildRelations } from ".";
|
||||
import { DiscordApiErrors } from "../util/Constants";
|
||||
import { OrmUtils } from "@fosscord/util";
|
||||
import { OrmUtils } from "typeorm/util/OrmUtils";
|
||||
|
||||
export const MemberPrivateProjection: (keyof Member)[] = [
|
||||
"id",
|
||||
@@ -71,7 +71,7 @@ export class Member extends BaseClassWithoutId {
|
||||
|
||||
@Column({ nullable: true })
|
||||
nick?: string;
|
||||
|
||||
|
||||
@JoinTable({
|
||||
name: "member_roles",
|
||||
joinColumn: { name: "index", referencedColumnName: "index" },
|
||||
@@ -103,14 +103,14 @@ export class Member extends BaseClassWithoutId {
|
||||
|
||||
@Column({ nullable: true })
|
||||
last_message_id?: string;
|
||||
|
||||
|
||||
/**
|
||||
@JoinColumn({ name: "id" })
|
||||
@ManyToOne(() => User, {
|
||||
onDelete: "DO NOTHING",
|
||||
// do not auto-kick force-joined members just because their joiners left the server
|
||||
}) **/
|
||||
@Column({ nullable: true})
|
||||
@Column({ nullable: true })
|
||||
joined_by?: string;
|
||||
|
||||
// TODO: add this when we have proper read receipts
|
||||
@@ -129,7 +129,7 @@ export class Member extends BaseClassWithoutId {
|
||||
|
||||
// use promise all to execute all promises at the same time -> save time
|
||||
//TODO: check for bugs
|
||||
if(guild.member_count) guild.member_count--;
|
||||
if (guild.member_count) guild.member_count--;
|
||||
return Promise.all([
|
||||
Member.delete({
|
||||
id: user_id,
|
||||
@@ -263,7 +263,7 @@ export class Member extends BaseClassWithoutId {
|
||||
pending: false,
|
||||
};
|
||||
//TODO: check for bugs
|
||||
if(guild.member_count) guild.member_count++;
|
||||
if (guild.member_count) guild.member_count++;
|
||||
await Promise.all([
|
||||
OrmUtils.mergeDeep(new Member(), {
|
||||
...member,
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { Column, Entity, FindOneOptions, FindOptionsSelectByString, JoinColumn, ManyToMany, OneToMany, RelationId} from "typeorm";
|
||||
import { OrmUtils } from "@fosscord/util";
|
||||
import { Column, Entity, FindOneOptions, FindOptionsSelectByString, JoinColumn, OneToMany } from "typeorm";
|
||||
import { OrmUtils } from "typeorm/util/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 { Note } from "./Note";
|
||||
|
||||
export enum PublicUserEnum {
|
||||
username,
|
||||
|
||||
@@ -5,7 +5,7 @@ import fs from "fs";
|
||||
// TODO: yaml instead of json
|
||||
// const overridePath = path.join(process.cwd(), "config.json");
|
||||
|
||||
let config: ConfigValue;
|
||||
let config: ConfigValue = DefaultConfigOptions;
|
||||
let pairs: ConfigEntity[];
|
||||
|
||||
// TODO: use events to inform about config updates
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
export * from "./ApiError";
|
||||
export * from "./BitField";
|
||||
export * from "./Token";
|
||||
export * from "./imports/HTTPError";
|
||||
export * from "./imports/OrmUtils";
|
||||
//export * from "./Categories";
|
||||
export * from "./cdn";
|
||||
export * from "./Config";
|
||||
@@ -21,4 +23,4 @@ export * from "./Array";
|
||||
export * from "./TraverseDirectory";
|
||||
export * from "./InvisibleCharacters";
|
||||
|
||||
export * from "./imports/index"
|
||||
export * from "./imports/index";
|
||||
|
||||
Reference in New Issue
Block a user