about summary refs log tree commit diff
path: root/src/lib/api/build-suggested-posts.ts
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2023-03-06 15:34:22 -0600
committerGitHub <noreply@github.com>2023-03-06 15:34:22 -0600
commit36791e68b3214cab9714a29d40fd7ecae2794c5e (patch)
tree47d5703595de08c5e5eff874285ae47b7a2a0427 /src/lib/api/build-suggested-posts.ts
parent74c30c60b8b5e68176b1447524db7e725f75a372 (diff)
downloadvoidsky-36791e68b3214cab9714a29d40fd7ecae2794c5e.tar.zst
Onboarding tweaks (#272)
* Small fix to side menu rendering

* Change onboarding to use an explicit 'is onboarding' mode to more clearly control the flow

* Add a progress bar to the welcome banner

* Dont show the 'unfollow button' on posts in weird times (close #271)

* Improve the empty state of the feed

* Only suggest recent posts
Diffstat (limited to 'src/lib/api/build-suggested-posts.ts')
-rw-r--r--src/lib/api/build-suggested-posts.ts21
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,