diff options
| author | Guillermo Serrahima <dev@vylion.com> | 2026-03-20 00:55:06 +0100 |
|---|---|---|
| committer | Guillermo Serrahima <dev@vylion.com> | 2026-03-20 00:55:06 +0100 |
| commit | c2472b20ae056bee40cec95fe11bbbef04651d52 (patch) | |
| tree | a2d25309088f1204cae6f22a97e43a44a6f90969 /backend/notes/note.go | |
| parent | 1d947b771995399b677c040136ef2cf88b33d4f2 (diff) | |
| download | llostre-c2472b20ae056bee40cec95fe11bbbef04651d52.tar.xz llostre-c2472b20ae056bee40cec95fe11bbbef04651d52.zip | |
recursive fetching of reply parents + thread deduplication
Diffstat (limited to 'backend/notes/note.go')
| -rw-r--r-- | backend/notes/note.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/backend/notes/note.go b/backend/notes/note.go index 3b32aa1..591caff 100644 --- a/backend/notes/note.go +++ b/backend/notes/note.go @@ -1,6 +1,7 @@ package notes import ( + "sort" "time" ) @@ -24,3 +25,42 @@ type Facet struct { Type string `json:"type"` Value string `json:"value"` // the link destination, whether url, profile or tag } + +func isChainContained(smallChain, bigChain []string) bool { + if len(smallChain) > len(bigChain) { + return false + } + + // check if smallChain is a suffix of bigChain + offset := len(bigChain) - len(smallChain) + for i, uri := range smallChain { + if bigChain[offset+i] != uri { + return false + } + } + return true +} + +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) + }) + + filtered := []Note{} + for _, post := range posts { + 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 { + isRedundant = true + break + } + } + if !isRedundant { + filtered = append(filtered, post) + } + } + + return filtered +} |
