aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorGuillermo Serrahima <dev@vylion.com>2026-03-21 02:21:37 +0100
committerGuillermo Serrahima <dev@vylion.com>2026-03-21 02:21:37 +0100
commit41b2943dba9993bd4b8c5a6e4546d8e23dce7662 (patch)
tree29920b0a65dcf702dc60dbfd2d9b5122c97a1752 /backend
parentad8a4cdc3ea5040b7732bc9e6e3090690a1032b1 (diff)
downloadllostre-41b2943dba9993bd4b8c5a6e4546d8e23dce7662.tar.xz
llostre-41b2943dba9993bd4b8c5a6e4546d8e23dce7662.zip
Changed parents string array to Note array + rendering threads in frontend
Diffstat (limited to 'backend')
-rw-r--r--backend/fetchers/app.bsky.feed.go20
-rw-r--r--backend/notes/note.go8
2 files changed, 11 insertions, 17 deletions
diff --git a/backend/fetchers/app.bsky.feed.go b/backend/fetchers/app.bsky.feed.go
index 5d87cca..4c6b92f 100644
--- a/backend/fetchers/app.bsky.feed.go
+++ b/backend/fetchers/app.bsky.feed.go
@@ -136,24 +136,18 @@ func parseAppBskyFeedPostCollection(logger *slog.Logger, slingshotURL string, se
return notes.DeduplicateThreads(posts), nil
}
-func FetchParents(logger *slog.Logger, replyToURI string, slingshotURL string, session *auth.OAuthState, cache *Cache, maxDepth int) ([]string, error) {
- parents := []string{}
- seen := make(map[string]bool)
+func FetchParents(logger *slog.Logger, replyToURI string, slingshotURL string, session *auth.OAuthState, cache *Cache, maxDepth int) ([]notes.Note, error) {
+ parents := []notes.Note{}
currentURI := replyToURI
for currentURI != "" {
- // check for circular reference
- if seen[currentURI] {
- logger.Warn("circular reference detected in thread", "uri", currentURI)
- break
- }
- seen[currentURI] = true
-
note, err := GetAppBskyFeedPostByURI(logger, currentURI, slingshotURL, session, cache)
if err != nil {
logger.Warn("failed to fetch parent", "uri", currentURI, "error", err)
- cache.Set(currentURI, notes.MissingNote(currentURI))
- parents = append(parents, currentURI)
+ note = notes.MissingNote(currentURI)
+
+ cache.Set(currentURI, note)
+ parents = append(parents, *note)
break
}
@@ -168,7 +162,7 @@ func FetchParents(logger *slog.Logger, replyToURI string, slingshotURL string, s
go FetchAppBskyFeedPosts(logger, note.AuthorDID, authorPDS, slingshotURL, session, cache)
}
- parents = append(parents, currentURI)
+ parents = append(parents, *note)
if note.ReplyTo == nil {
break
diff --git a/backend/notes/note.go b/backend/notes/note.go
index 569188c..36b9f2b 100644
--- a/backend/notes/note.go
+++ b/backend/notes/note.go
@@ -16,7 +16,7 @@ type Note struct {
CreatedAt time.Time `json:"createdAt"`
ReplyTo *string `json:"replyTo,omitempty"`
Facets []Facet `json:"facets,omitempty"`
- Parents []string `json:"parents,omitempty"`
+ Parents []Note `json:"parents,omitempty"`
}
type Facet struct {
@@ -35,15 +35,15 @@ func MissingNote(uri string) *Note {
}
}
-func isChainContained(smallChain, bigChain []string) bool {
+func isChainContained(smallChain, bigChain []Note) 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 {
+ for i, note := range smallChain {
+ if bigChain[offset+i].URI != note.URI {
return false
}
}