diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/state/queries/post-thread.ts | 20 |
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, |