mirror of
https://github.com/spacebarchat/server.git
synced 2026-12-05 00:24:13 +00:00
Resolve some TODOs
This commit is contained in:
1 parent
340c2efac5
commit
0cd981e500
41 files changed
+628
-152
No files matched your search
@@ -76,9 +76,7 @@ export class BaseClassWithoutId extends BaseEntity {
|
||||
return this;
|
||||
}
|
||||
|
||||
// TODO: fix eslint
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
toJSON(): any {
|
||||
toJSON(): unknown {
|
||||
this.clean_data();
|
||||
return Object.fromEntries(
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
|
||||
@@ -21,6 +21,8 @@ import { arrayRemove } from "@spacebar/extensions";
|
||||
import { Config, handleFile, Snowflake } from "@spacebar/util";
|
||||
import {
|
||||
DiscoverableGuild,
|
||||
DiscoveryCategory,
|
||||
EmojiResponse,
|
||||
GuildNsfwLevel,
|
||||
GuildPremiumTier,
|
||||
GuildProfileResponse,
|
||||
@@ -28,6 +30,7 @@ import {
|
||||
GuildVisibilityLevel,
|
||||
GuildWelcomeScreen,
|
||||
IntegrationGuild,
|
||||
StickerResponse,
|
||||
} from "@spacebar/schemas";
|
||||
import { Ban } from "./Ban";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
@@ -342,9 +345,9 @@ export class Guild extends BaseClass {
|
||||
},
|
||||
},
|
||||
}),*/
|
||||
emojis: this.emojis?.map((e) => e.toJSON()) ?? undefined,
|
||||
emojis: (this.emojis?.map((e) => e.toJSON()) as EmojiResponse[]) ?? undefined,
|
||||
emoji_count: this.emojis ? this.emojis.length : undefined,
|
||||
stickers: this.stickers?.map((s) => s.toJSON()) ?? undefined,
|
||||
stickers: (this.stickers?.map((s) => s.toJSON()) as StickerResponse[]) ?? undefined,
|
||||
sticker_count: this.stickers ? this.stickers.length : undefined,
|
||||
auto_removed: false,
|
||||
primary_category_id: this.primary_category_id!,
|
||||
@@ -353,13 +356,13 @@ export class Guild extends BaseClass {
|
||||
reasons_to_join: [],
|
||||
created_at: new Date(Snowflake.deconstruct(this.id).timestamp).toISOString(), // TODO: make column
|
||||
primary_category: this.primary_category_id
|
||||
? (
|
||||
? ((
|
||||
await Categories.findOneOrFail({
|
||||
where: {
|
||||
id: this.primary_category_id!,
|
||||
},
|
||||
})
|
||||
).toJSON()
|
||||
).toJSON() as DiscoveryCategory)
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import { Channel } from "./Channel";
|
||||
import { Guild } from "./Guild";
|
||||
import { Member } from "./Member";
|
||||
import { User } from "./User";
|
||||
import { InviteType, PublicInvite } from "@spacebar/schemas/api/guilds/Invite";
|
||||
import { InviteCreateEventData, InviteType, PublicInvite } from "@spacebar/schemas/api/guilds/Invite";
|
||||
|
||||
export const PublicInviteRelation = ["inviter", "guild", "channel"];
|
||||
|
||||
@@ -105,6 +105,7 @@ export class Invite extends BaseClassWithoutId {
|
||||
if (this.max_uses !== 0 && this.uses >= this.max_uses) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
toPublicJSON(): PublicInvite {
|
||||
return {
|
||||
code: this.code,
|
||||
@@ -128,6 +129,26 @@ export class Invite extends BaseClassWithoutId {
|
||||
};
|
||||
}
|
||||
|
||||
toGatewayInviteCreateData(): InviteCreateEventData {
|
||||
return {
|
||||
code: this.code,
|
||||
type: InviteType.GUILD, // TODO: support other invite types
|
||||
channel_id: this.channel_id ?? this.channel.id,
|
||||
guild_id: this.guild_id ?? this.channel.guild_id,
|
||||
inviter: this.inviter.toPartialUser(),
|
||||
expires_at: this.expires_at?.toString() ?? null,
|
||||
target_type: undefined, // TODO
|
||||
target_user: undefined, // TODO
|
||||
created_at: this.created_at.toISOString(),
|
||||
max_age: this.max_age,
|
||||
max_uses: this.max_uses,
|
||||
temporary: this.temporary,
|
||||
uses: this.uses,
|
||||
role_ids: [], // TODO
|
||||
target_application: undefined, // TODO
|
||||
} satisfies InviteCreateEventData;
|
||||
}
|
||||
|
||||
static async joinGuild(user_id: string, code: string) {
|
||||
const invite = await Invite.findOneOrFail({ where: { code } });
|
||||
if (invite.isExpired()) {
|
||||
|
||||
@@ -390,7 +390,7 @@ export class Message extends BaseClass {
|
||||
embeds: this.embeds,
|
||||
flags: this.flags,
|
||||
mention_roles: this.mention_roles?.map((x) => x.id),
|
||||
mentions: this.mentions.map((x) => x.toPublicUser() as unknown as PartialUser), // TODO: write a proper method for this
|
||||
mentions: this.mentions.map((x) => x.toPartialUser()),
|
||||
timestamp: this.timestamp,
|
||||
type: this.type,
|
||||
},
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
import { Column, Entity, JoinColumn, ManyToOne } from "typeorm";
|
||||
import { Tag as Tag_ } from "@spacebar/schemas";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { Channel } from "./Channel";
|
||||
|
||||
@@ -45,13 +46,13 @@ export class Tag extends BaseClass {
|
||||
@Column({ nullable: true })
|
||||
emoji_name?: string;
|
||||
|
||||
toJSON() {
|
||||
toJSON(): Tag_ {
|
||||
return {
|
||||
name: this.name,
|
||||
id: this.id,
|
||||
moderated: this.moderated,
|
||||
emoji_id: this.emoji_id,
|
||||
emoji_name: this.emoji_name,
|
||||
emoji_id: this.emoji_id ?? null,
|
||||
emoji_name: this.emoji_name ?? null,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -18,27 +18,13 @@
|
||||
|
||||
import { Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn, RelationId } from "typeorm";
|
||||
import { ThreadMembersUpdateEvent } from "../../util/interfaces";
|
||||
import { HTTPError } from "lambert-server/HTTPError";
|
||||
import { emitEvent } from "@spacebar/util/util";
|
||||
import { MuteConfig, PublicThreadMember, ThreadMemberFlags } from "@spacebar/schemas";
|
||||
import { BaseClassWithoutId } from "./BaseClass";
|
||||
import { Channel } from "./Channel";
|
||||
import { HTTPError } from "lambert-server/HTTPError";
|
||||
import { Member } from "./Member";
|
||||
|
||||
// TODO: move
|
||||
interface ThreadMemberMuteConfig {
|
||||
end_time?: Date;
|
||||
selected_time_window?: number;
|
||||
}
|
||||
|
||||
// TODO: move
|
||||
export enum ThreadMemberFlags {
|
||||
NONE = 0,
|
||||
HAS_INTERACTED = 1 << 0,
|
||||
ALL_MESSAGES = 1 << 1,
|
||||
ONLY_MENTIONS = 1 << 2,
|
||||
NO_MESSAGES = 1 << 3,
|
||||
}
|
||||
|
||||
@Entity("thread_members")
|
||||
@Index(["id", "member_idx"], { unique: true })
|
||||
export class ThreadMember extends BaseClassWithoutId {
|
||||
@@ -72,7 +58,7 @@ export class ThreadMember extends BaseClassWithoutId {
|
||||
muted: boolean;
|
||||
|
||||
@Column({ nullable: true, type: "jsonb" })
|
||||
mute_config?: ThreadMemberMuteConfig;
|
||||
mute_config?: MuteConfig;
|
||||
|
||||
@Column()
|
||||
flags: ThreadMemberFlags;
|
||||
@@ -93,20 +79,18 @@ export class ThreadMember extends BaseClassWithoutId {
|
||||
}))
|
||||
)
|
||||
throw new HTTPError("You are not member of this thread", 403);
|
||||
// // use promise all to execute all promises at the same time -> save time
|
||||
// TODO: check for bugs
|
||||
|
||||
if (channel.member_count) channel.member_count--;
|
||||
return Promise.all([
|
||||
ThreadMember.delete({
|
||||
id: thread_id,
|
||||
member_idx: member_id,
|
||||
}),
|
||||
// //Guild.decrement({ id: guild_id }, "member_count", -1),
|
||||
|
||||
emitEvent({
|
||||
event: "THREAD_MEMBERS_UPDATE",
|
||||
data: {
|
||||
guild_id: channel.guild_id!, // TODO: is this the right fix?
|
||||
guild_id: channel.guild_id!,
|
||||
id: channel.id,
|
||||
member_count: channel.member_count ?? 0,
|
||||
removed_member_ids: [member_id],
|
||||
@@ -116,6 +100,18 @@ export class ThreadMember extends BaseClassWithoutId {
|
||||
]);
|
||||
}
|
||||
|
||||
toJSON(): PublicThreadMember {
|
||||
return {
|
||||
id: this.id,
|
||||
flags: this.flags,
|
||||
join_timestamp: this.join_timestamp.toISOString(),
|
||||
member: this.member.toPublicMember(),
|
||||
mute_config: this.mute_config,
|
||||
muted: this.muted,
|
||||
user_id: this.member.id,
|
||||
} satisfies PublicThreadMember;
|
||||
}
|
||||
|
||||
// static async addRole(user_id: string, guild_id: string, role_id: string) {
|
||||
// const [member, role] = await Promise.all([
|
||||
// // @ts-ignore
|
||||
|
||||
Reference in new issue
Block a user