aboutsummaryrefslogtreecommitdiff
path: root/backend/notes/note.go
diff options
context:
space:
mode:
Diffstat (limited to 'backend/notes/note.go')
-rw-r--r--backend/notes/note.go17
1 files changed, 8 insertions, 9 deletions
diff --git a/backend/notes/note.go b/backend/notes/note.go
index c427a8f..8a73b70 100644
--- a/backend/notes/note.go
+++ b/backend/notes/note.go
@@ -35,23 +35,22 @@ func MissingNote(uri string) *Note {
}
}
-func isChainContained(smallChain, bigChain []Note) bool {
- if len(smallChain) > len(bigChain) {
+func isChainContained(smallChainPost, bigChainPost Note) bool {
+ if len(smallChainPost.Parents) > len(bigChainPost.Parents) {
return false
}
- // check if smallChain is a suffix of bigChain
- offset := len(bigChain) - len(smallChain)
- for i, note := range smallChain {
- if bigChain[offset+i].URI != note.URI {
+ // 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
}
}
- return true
+ return smallChainPost.URI == bigChainPost.Parents[offset-1].URI
}
func DeduplicateThreads(posts []Note) []Note {
- // sort by parent chain length (longest first)
sort.Slice(posts, func(i, j int) bool {
return len(posts[i].Parents) > len(posts[j].Parents)
})
@@ -61,7 +60,7 @@ func DeduplicateThreads(posts []Note) []Note {
isRedundant := false
for _, kept := range filtered {
// check if this post's chain is contained in any kept post
- if isChainContained(post.Parents, kept.Parents) && post.URI == kept.URI {
+ if isChainContained(post, kept) {
isRedundant = true
break
}