about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2023-09-01 11:54:51 -0700
committerGitHub <noreply@github.com>2023-09-01 11:54:51 -0700
commit3e96373903b337f4883e706efee88b47511734a6 (patch)
tree14d3b804eb196ade4bf97844b78fc0081553dea8 /src
parent4cd3ddecadfaad1e1711b916760590cd18fba675 (diff)
downloadvoidsky-3e96373903b337f4883e706efee88b47511734a6.tar.zst
Sort thread replies by likes (#1356)
* Sort replies by likes

* Types fix
Diffstat (limited to 'src')
-rw-r--r--src/state/models/content/post-thread.ts6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/state/models/content/post-thread.ts b/src/state/models/content/post-thread.ts
index 85ed13cb4..7e3650948 100644
--- a/src/state/models/content/post-thread.ts
+++ b/src/state/models/content/post-thread.ts
@@ -296,7 +296,11 @@ function sortThread(item: MaybeThreadItem) {
       if (modScore(a.moderation) !== modScore(b.moderation)) {
         return modScore(a.moderation) - modScore(b.moderation)
       }
-      return b.post.indexedAt.localeCompare(a.post.indexedAt) // newest
+      if (a.post.likeCount === b.post.likeCount) {
+        return b.post.indexedAt.localeCompare(a.post.indexedAt) // newest
+      } else {
+        return (b.post.likeCount || 0) - (a.post.likeCount || 0) // most likes
+      }
     })
     item.replies.forEach(reply => sortThread(reply))
   }