diff --git a/src/api/routes/channels/#channel_id/messages/index.ts b/src/api/routes/channels/#channel_id/messages/index.ts index ca3db0134..20b3ab226 100644 --- a/src/api/routes/channels/#channel_id/messages/index.ts +++ b/src/api/routes/channels/#channel_id/messages/index.ts @@ -508,7 +508,7 @@ router.post( channel_id: channel_id, data: message.toJSON(), } satisfies MessageCreateEvent), - message.guild_id ? Member.update({ id: req.user_id, guild_id: message.guild_id }, { last_message_id: message.id }) : null, + message.guild_id ? Member.update({ id: req.user_id, guild_id: message.guild_id }, { last_message_id: message.id }) : undefined, ]); // no await as it shouldnt block the message send function and silently catch error diff --git a/src/api/routes/channels/#channel_id/typing.ts b/src/api/routes/channels/#channel_id/typing.ts index 0db9dae4f..363316478 100644 --- a/src/api/routes/channels/#channel_id/typing.ts +++ b/src/api/routes/channels/#channel_id/typing.ts @@ -58,7 +58,7 @@ router.post( channel_id, timestamp, user_id, - guild_id: channel.guild_id, + guild_id: channel.guild_id ?? undefined, }, } satisfies TypingStartEvent); diff --git a/src/util/entities/Channel.ts b/src/util/entities/Channel.ts index 611351aa4..451500cb3 100644 --- a/src/util/entities/Channel.ts +++ b/src/util/entities/Channel.ts @@ -704,15 +704,10 @@ export class Channel extends BaseClass { } toJSON(): PublicChannel { - // needed as some CHANNEL_UPDATE event doesn't call the calculatePosition function and doesn't populate - // the position field. Needs to be looked into more - // TODO: Look into when this can be undefined during CHANNEL_UPDATE - if (this.position === undefined) { - this.position = 0; - } return { ...this, last_pin_timestamp: this.last_pin_timestamp?.toISOString(), + guild_id: this.guild_id ?? undefined, recipients: undefined, //this.recipients?.map(x=>x.user.toPublicUser()), // TODO: fix me owner: undefined, // TODO: fix me - this is thread owner diff --git a/src/util/entities/Message.ts b/src/util/entities/Message.ts index 419be00fd..cfac909af 100644 --- a/src/util/entities/Message.ts +++ b/src/util/entities/Message.ts @@ -33,7 +33,13 @@ import { ApplicationCommandType, BaseMessageComponents, Embed, - MessageComponentType, MessageSnapshot, MessageType, PartialMessage, Poll, PublicMessage, Reaction, + MessageComponentType, + MessageSnapshot, + MessageType, + PartialMessage, + Poll, + PublicMessage, + Reaction, UnfurledMediaItem, } from "@spacebar/schemas"; import { PartialUser } from "@spacebar/schemas"; @@ -78,56 +84,46 @@ export class Message extends BaseClass { @ManyToOne(() => Guild, { onDelete: "CASCADE", }) - @JsonRemoveEmpty guild?: Guild; @Column({ nullable: true }) @RelationId((message: Message) => message.author) @Index() - @JsonRemoveEmpty author_id?: string; @JoinColumn({ name: "author_id", referencedColumnName: "id" }) @ManyToOne(() => User, { onDelete: "CASCADE", }) - @JsonRemoveEmpty author?: User; @Column({ nullable: true }) @RelationId((message: Message) => message.member) - @JsonRemoveEmpty member_id?: string; @JoinColumn({ name: "member_id", referencedColumnName: "id" }) @ManyToOne(() => User, { onDelete: "CASCADE", }) - @JsonRemoveEmpty member?: Member; @Column({ nullable: true }) @RelationId((message: Message) => message.webhook) - @JsonRemoveEmpty webhook_id?: string; @JoinColumn({ name: "webhook_id" }) @ManyToOne(() => Webhook) - @JsonRemoveEmpty webhook?: Webhook; @Column({ nullable: true }) @RelationId((message: Message) => message.application) - @JsonRemoveEmpty application_id?: string; @JoinColumn({ name: "application_id" }) @ManyToOne(() => Application) - @JsonRemoveEmpty application?: Application; @Column({ nullable: true }) - @JsonRemoveEmpty content?: string; @Column() @@ -172,15 +168,12 @@ export class Message extends BaseClass { embeds: Embed[]; @Column({ type: "simple-json" }) - @JsonRemoveEmpty reactions: Reaction[]; @Column({ type: "text", nullable: true }) - @JsonRemoveEmpty nonce?: string; @Column({ nullable: true, type: Date }) - @JsonRemoveEmpty pinned_at?: Date | null; get pinned(): boolean { @@ -272,6 +265,7 @@ export class Message extends BaseClass { } toJSON(shallow = false): PublicMessage { + this.clean_data(); return { ...this, channel_id: this.channel_id ?? this.channel.id,