-
-
Notifications
You must be signed in to change notification settings - Fork 252
fix: getting message pinss #1313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
src/util/entities/Message.ts
Outdated
pinned?: boolean; | ||
|
||
@Column({ nullable: true }) | ||
pinned_at?: Date; |
There was a problem hiding this comment.
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
There was a problem hiding this 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, |
There was a problem hiding this comment.
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; | ||
|
There was a problem hiding this comment.
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:
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"`); |
There was a problem hiding this comment.
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
Before:


After: