aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillermo Serrahima <dev@vylion.com>2026-03-21 16:32:17 +0100
committerGuillermo Serrahima <dev@vylion.com>2026-03-21 16:32:17 +0100
commit2bd2e1fd4fcf147ff4bb229226d879b6b6b5fa78 (patch)
treea630e6e88e5d8c852f50dc59c5af282b8e1d5271
parent7cd27b77a530f4daa291165d817d3961af8d70f6 (diff)
downloadllostre-2bd2e1fd4fcf147ff4bb229226d879b6b6b5fa78.tar.xz
llostre-2bd2e1fd4fcf147ff4bb229226d879b6b6b5fa78.zip
Fix thread deduplication pt. 2
-rw-r--r--backend/notes/note.go15
1 files changed, 9 insertions, 6 deletions
diff --git a/backend/notes/note.go b/backend/notes/note.go
index 8a73b70..7ef537f 100644
--- a/backend/notes/note.go
+++ b/backend/notes/note.go
@@ -40,13 +40,16 @@ func isChainContained(smallChainPost, bigChainPost Note) bool {
return false
}
- // check if parents of smallChainPost are included in bigChainPost
- offset := len(bigChainPost.Parents) - len(smallChainPost.Parents)
- for i, note := range smallChainPost.Parents {
- if bigChainPost.Parents[offset+i].URI != note.URI {
- return false
- }
+ // if the thread is going to differ at any post, it's going to be at the end
+ // thus if the posts match their parents MUST match too
+ // (not that I expect to ever compare a post to itself but this way it won't break if I do. And technically a thread contains itself)
+ if len(smallChainPost.Parents) == len(bigChainPost.Parents) {
+ return smallChainPost.URI == bigChainPost.URI
}
+
+ // check if the last post of the smaller chain is the (n+1)-th post of the bigger chain
+ // where n is the number of parents in the smaller reply chain
+ offset := len(bigChainPost.Parents) - len(smallChainPost.Parents)
return smallChainPost.URI == bigChainPost.Parents[offset-1].URI
}