Skip to content

Commit

Permalink
fix: sort manually fetched messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Lemmmy committed Jul 18, 2024
1 parent 509ed88 commit ddda811
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/modules/ForumPinner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ export default class ForumPinner extends Module {
// fetchStarterMessage should work (the first message of a thread has the same ID as the thread itself), but fall
// back to fetching all messages if it doesn't work for some reason
const firstMessage = (await thread.fetchStarterMessage().catch(() => null))
?? await thread.messages.fetch().then(m => m.first());
?? await thread.messages.fetch().then(m => m
.sort((a, b) => a.createdTimestamp - b.createdTimestamp) // Sort by creation time ascending
.first());

if (DEBUG) console.log(`First message: ${firstMessage?.id}`);
if (!firstMessage) throw new Error("No messages found in thread!");
Expand Down

0 comments on commit ddda811

Please sign in to comment.