From 2bd2e1fd4fcf147ff4bb229226d879b6b6b5fa78 Mon Sep 17 00:00:00 2001 From: Guillermo Serrahima Date: Sat, 21 Mar 2026 16:32:17 +0100 Subject: Fix thread deduplication pt. 2 --- backend/notes/note.go | 15 +++++++++------ 1 file 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 } -- cgit v1.2.3