Skip to content

Conversation

CyberL1
Copy link
Contributor

@CyberL1 CyberL1 commented Jul 13, 2025

Before:
obraz
After:
obraz

pinned?: boolean;

@Column({ nullable: true })
pinned_at?: Date;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo it would be better to remove the pinned column entirely and just use this date column to check if it's pinned

Copy link
Member

@TheArcaneBrony TheArcaneBrony left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldnt this require changes in gateway etc?

mentions: new_message.embeds,
mention_roles: new_message.mention_roles,
mention_everyone: new_message.mention_everyone,
pinned: new_message.pinned,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was supposed to be a thread, oops

pinned?: boolean;
@Column({ type: "timestamp", nullable: true })
pinned_at: Date | null;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add a computed property so we don't have to do a null check on pinned_at every time we want to check if it's pinned:

Suggested change
get pinned(): boolean {
return this.pinned_at != null
}

and then we also have to add it to the toJSON() method since getters aren't serialized when we have to do JSON.stringify on the object:

toJSON(): Message {
		return {
			...this,
			author_id: undefined,
			member_id: undefined,
			webhook_id: this.webhook_id ?? undefined,
			application_id: undefined,

			nonce: this.nonce ?? undefined,
			tts: this.tts ?? false,
			guild: this.guild ?? undefined,
			webhook: this.webhook ?? undefined,
			interaction: this.interaction ?? undefined,
			reactions: this.reactions ?? undefined,
			sticker_items: this.sticker_items ?? undefined,
			message_reference: this.message_reference ?? undefined,
			author: {
				...(this.author?.toPublicUser() ?? undefined),
				// Webhooks
				username: this.username ?? this.author?.username,
				avatar: this.avatar ?? this.author?.avatar,
			},
			activity: this.activity ?? undefined,
			application: this.application ?? undefined,
			components: this.components ?? undefined,
			poll: this.poll ?? undefined,
			content: this.content ?? "",
                        pinned: this.pinned,
		};
	}

await queryRunner.query(
`ALTER TABLE "messages" ADD "pinned_at" TIMESTAMP`,
);
await queryRunner.query(`ALTER TABLE "messages" DROP COLUMN "pinned"`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR looks good to me, only missing migrating old pinned messages to the new format. Probably just fetch all the messages that are pinned, then set the pinned_at timestamp to current time since we don't know when it was pinned, and finally drop the old pinned column

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants