Fix Typing event so that it returns undefined rather than null

Added clean data to message entity so it respects json tags.
This commit is contained in:
whinis
2026-03-29 09:15:33 -04:00
committed by Rory&
parent f9147b78ca
commit 310d292e9a
4 changed files with 11 additions and 22 deletions
@@ -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
@@ -58,7 +58,7 @@ router.post(
channel_id,
timestamp,
user_id,
guild_id: channel.guild_id,
guild_id: channel.guild_id ?? undefined,
},
} satisfies TypingStartEvent);
+1 -6
View File
@@ -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
+8 -14
View File
@@ -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,