+65
-11
main.go
+65
-11
main.go
···
569
569
ctx,
570
570
skeletonposts,
571
571
20,
572
-
func(ctx context.Context, raw *appbsky.FeedDefs_SkeletonFeedPost) (*appbsky.FeedDefs_FeedViewPost, error) {
572
+
func(ctx context.Context, raw *appbsky.FeedDefs_SkeletonFeedPost, idx int) (*appbsky.FeedDefs_FeedViewPost, error) {
573
573
post, _, err := appbskyfeeddefs.PostView(ctx, raw.Post, sl, cs, BSKYIMAGECDN_URL, viewer, 2)
574
574
if err != nil {
575
575
return nil, err
···
651
651
//var thread []*appbsky.UnspeccedGetPostThreadOtherV2_ThreadItem
652
652
653
653
var skeletonposts []string
654
-
skeletonposts = append(skeletonposts, threadAnchorURI.String())
655
654
656
655
emptystrarray := &[]string{}
657
656
limit := 100
658
657
658
+
// recurse to the top
659
+
parentsMap := map[string]*appbsky.FeedDefs_PostView{}
660
+
current := threadAnchorURI
661
+
iteration := 0
662
+
for true {
663
+
iteration = iteration + 1
664
+
if iteration > 10 {
665
+
break
666
+
}
667
+
recordaturi, err := syntax.ParseATURI("at://" + current.Authority().String() + "/" + string(current.Collection()) + "/" + string(current.RecordKey()))
668
+
if err != nil {
669
+
break
670
+
}
671
+
// loop
672
+
postView, postRecord, err := appbskyfeeddefs.PostView(ctx, recordaturi.String(), sl, cs, BSKYIMAGECDN_URL, viewer, 3)
673
+
if err != nil {
674
+
break
675
+
}
676
+
if postView == nil {
677
+
break
678
+
}
679
+
//if iteration != 1 {
680
+
skeletonposts = append([]string{recordaturi.String()}, skeletonposts...)
681
+
//}
682
+
parentsMap[recordaturi.String()] = postView
683
+
if postRecord != nil && postRecord.Reply != nil && postRecord.Reply.Parent != nil && postRecord.Reply.Root != nil {
684
+
if postRecord.Reply.Parent.Uri == postRecord.Reply.Root.Uri {
685
+
//break
686
+
iteration = 9
687
+
}
688
+
689
+
current, err = syntax.ParseATURI(postRecord.Reply.Parent.Uri)
690
+
if err != nil {
691
+
break
692
+
}
693
+
} else {
694
+
log.Println("what huh what hwat")
695
+
break //whatt
696
+
}
697
+
698
+
}
699
+
700
+
//skeletonposts = append(skeletonposts, threadAnchorURI.String())
659
701
// todo: theres a cursor!!! pagination please!
660
-
// todo: also i doubt im gonna do proper threadding so make sure to remind me to do it properly thanks
702
+
// todo: also i doubt im gonna do proper threadding right now, so make sure to remind me to do it properly some time later thanks
661
703
//rootReplies, _ := constellation.GetBacklinks(ctx, cs, string(threadAnchorURI), "app.bsky.feed.post:reply.root.uri", *emptystrarray, &limit, nil)
662
704
parentReplies, _ := constellation.GetBacklinks(ctx, cs, string(threadAnchorURI), "app.bsky.feed.post:reply.parent.uri", *emptystrarray, &limit, nil)
663
705
···
668
710
}
669
711
skeletonposts = append(skeletonposts, recordaturi.String())
670
712
}
713
+
maplen := len(parentsMap)
671
714
concurrentResults := MapConcurrent(
672
715
ctx,
673
716
skeletonposts,
674
717
20,
675
-
func(ctx context.Context, raw string) (*appbsky.UnspeccedGetPostThreadOtherV2_ThreadItem, error) {
676
-
post, _, err := appbskyfeeddefs.PostView(ctx, raw, sl, cs, BSKYIMAGECDN_URL, viewer, 3)
677
-
if err != nil {
678
-
return nil, err
679
-
}
680
-
if post == nil {
681
-
return nil, fmt.Errorf("post not found")
718
+
func(ctx context.Context, raw string, idx int) (*appbsky.UnspeccedGetPostThreadOtherV2_ThreadItem, error) {
719
+
var postView *appbsky.FeedDefs_PostView
720
+
fromParentChain := false
721
+
postView, ok := parentsMap[raw]
722
+
if !ok {
723
+
post, _, err := appbskyfeeddefs.PostView(ctx, raw, sl, cs, BSKYIMAGECDN_URL, viewer, 3)
724
+
if err != nil {
725
+
return nil, err
726
+
}
727
+
if post == nil {
728
+
return nil, fmt.Errorf("post not found")
729
+
}
730
+
postView = post
731
+
} else {
732
+
fromParentChain = true
682
733
}
683
734
684
735
depth := int64(1)
685
736
if raw == threadAnchorURI.String() {
686
737
depth = 0
738
+
}
739
+
if fromParentChain {
740
+
depth = int64(0 - maplen + idx + 1)
687
741
}
688
742
689
743
return &appbsky.UnspeccedGetPostThreadOtherV2_ThreadItem{
···
713
767
// OpThread bool `json:"opThread" cborgen:"opThread"`
714
768
OpThread: false, // todo: placeholder
715
769
// Post *FeedDefs_PostView `json:"post" cborgen:"post"`
716
-
Post: post,
770
+
Post: postView,
717
771
},
718
772
},
719
773
}, nil
+2
-2
utils.go
+2
-2
utils.go
···
62
62
ctx context.Context,
63
63
items []T,
64
64
concurrencyLimit int,
65
-
mapper func(context.Context, T) (R, error),
65
+
mapper func(context.Context, T, int) (R, error),
66
66
) []AsyncResult[R] {
67
67
if len(items) == 0 {
68
68
return nil
···
86
86
return
87
87
}
88
88
89
-
val, err := mapper(ctx, input)
89
+
val, err := mapper(ctx, input, idx)
90
90
results[idx] = AsyncResult[R]{Value: val, Err: err}
91
91
}(i, item)
92
92
}