about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authordan <dan.abramov@gmail.com>2025-01-22 00:25:41 +0000
committerGitHub <noreply@github.com>2025-01-22 00:25:41 +0000
commit1403570a6a231099c35c977afe38f84349d92018 (patch)
treec406291e02408ccdd1c02aa9301eb9bf93724a78 /src
parent99d23d65e2e1d3500838570c9215280f7e263124 (diff)
downloadvoidsky-1403570a6a231099c35c977afe38f84349d92018.tar.zst
Adjust decay formula (#7535)
Diffstat (limited to 'src')
-rw-r--r--src/state/queries/post-thread.ts20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/state/queries/post-thread.ts b/src/state/queries/post-thread.ts
index 2ebaf4f7d..13ecce9a6 100644
--- a/src/state/queries/post-thread.ts
+++ b/src/state/queries/post-thread.ts
@@ -53,8 +53,9 @@ export type ThreadPost = {
   uri: string
   post: AppBskyFeedDefs.PostView
   record: AppBskyFeedPost.Record
-  parent?: ThreadNode
-  replies?: ThreadNode[]
+  parent: ThreadNode | undefined
+  replies: ThreadNode[] | undefined
+  hasOPLike: boolean | undefined
   ctx: ThreadCtx
 }
 
@@ -255,8 +256,8 @@ export function sortThread(
       if (aFetchedAt !== bFetchedAt) {
         return aFetchedAt - bFetchedAt // older fetches first
       } else if (opts.sort === 'hotness') {
-        const aHotness = getHotness(a.post, aFetchedAt)
-        const bHotness = getHotness(b.post, bFetchedAt /* same as aFetchedAt */)
+        const aHotness = getHotness(a, aFetchedAt)
+        const bHotness = getHotness(b, bFetchedAt /* same as aFetchedAt */)
         return bHotness - aHotness
       } else if (opts.sort === 'oldest') {
         return a.post.indexedAt.localeCompare(b.post.indexedAt)
@@ -309,7 +310,8 @@ export function sortThread(
 // We want to give recent comments a real chance (and not bury them deep below the fold)
 // while also surfacing well-liked comments from the past. In the future, we can explore
 // something more sophisticated, but we don't have much data on the client right now.
-function getHotness(post: AppBskyFeedDefs.PostView, fetchedAt: number) {
+function getHotness(threadPost: ThreadPost, fetchedAt: number) {
+  const {post, hasOPLike} = threadPost
   const hoursAgo = Math.max(
     0,
     (new Date(fetchedAt).getTime() - new Date(post.indexedAt).getTime()) /
@@ -318,7 +320,8 @@ function getHotness(post: AppBskyFeedDefs.PostView, fetchedAt: number) {
   const likeCount = post.likeCount ?? 0
   const likeOrder = Math.log(3 + likeCount)
   const timePenaltyExponent = 1.5 + 1.5 / (1 + Math.log(1 + likeCount))
-  const timePenalty = Math.pow(hoursAgo + 2, timePenaltyExponent)
+  const opLikeBoost = hasOPLike ? 0.85 : 1.0
+  const timePenalty = Math.pow(hoursAgo + 2, timePenaltyExponent * opLikeBoost)
   return likeOrder / timePenalty
 }
 
@@ -356,6 +359,8 @@ function responseToThreadNodes(
               // do not show blocked posts in replies
               .filter(node => node.type !== 'blocked')
           : undefined,
+      // @ts-ignore TODO: Update API package.
+      hasOPLike: Boolean(node?.threadContext?.rootAuthorLike),
       ctx: {
         depth,
         isHighlightedPost: depth === 0,
@@ -552,6 +557,7 @@ function threadNodeToPlaceholderThread(
     record: node.record,
     parent: undefined,
     replies: undefined,
+    hasOPLike: undefined,
     ctx: {
       depth: 0,
       isHighlightedPost: true,
@@ -573,6 +579,7 @@ function postViewToPlaceholderThread(
     record: post.record as AppBskyFeedPost.Record, // validated in notifs
     parent: undefined,
     replies: undefined,
+    hasOPLike: undefined,
     ctx: {
       depth: 0,
       isHighlightedPost: true,
@@ -594,6 +601,7 @@ function embedViewRecordToPlaceholderThread(
     record: record.value as AppBskyFeedPost.Record, // validated in getEmbeddedPost
     parent: undefined,
     replies: undefined,
+    hasOPLike: undefined,
     ctx: {
       depth: 0,
       isHighlightedPost: true,