diff options
Diffstat (limited to 'src/lib/api/build-suggested-posts.ts')
-rw-r--r-- | src/lib/api/build-suggested-posts.ts | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/lib/api/build-suggested-posts.ts b/src/lib/api/build-suggested-posts.ts index 6250f4a9c..defa45311 100644 --- a/src/lib/api/build-suggested-posts.ts +++ b/src/lib/api/build-suggested-posts.ts @@ -37,13 +37,20 @@ function mergePosts( // filter the feed down to the post with the most upvotes res.data.feed = res.data.feed.reduce( (acc: AppBskyFeedFeedViewPost.Main[], v) => { - if (!acc?.[0] && !v.reason) { + if ( + !acc?.[0] && + !v.reason && + !v.reply && + isRecentEnough(v.post.indexedAt) + ) { return [v] } if ( acc && !v.reason && - v.post.upvoteCount > acc[0].post.upvoteCount + !v.reply && + v.post.upvoteCount > acc[0]?.post.upvoteCount && + isRecentEnough(v.post.indexedAt) ) { return [v] } @@ -112,6 +119,16 @@ function isCombinedCursor(cursor: string) { return cursor.includes(',') } +const TWO_DAYS_AGO = Date.now() - 1e3 * 60 * 60 * 48 +function isRecentEnough(date: string) { + try { + const d = Number(new Date(date)) + return d > TWO_DAYS_AGO + } catch { + return false + } +} + export { getMultipleAuthorsPosts, mergePosts, |