1
0
Fork 0

Implemented reply chunks querying for #10

This commit is contained in:
マリウス 2023-01-10 14:03:57 -05:00
parent a4e4db91b7
commit 51cb1d971b
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F
2 changed files with 25 additions and 3 deletions

View File

@ -28,7 +28,9 @@ type Post struct {
Forum forum.Forum
Replies []reply.Reply
TotalReplies int
CurrentRepliesStartIDX int
Replies []reply.Reply
URL string

View File

@ -236,6 +236,9 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) {
SysIDX: sys.ID,
},
TotalReplies: 0,
CurrentRepliesStartIDX: -1,
URL: fmt.Sprintf("%s/t/%d", baseURL, i.ID),
SysIDX: sys.ID,
@ -254,11 +257,28 @@ func (sys *System) LoadPost(p *post.Post) error {
// API seems to return 20 posts by default. If the stream is greater than 20
// posts, we need to fetch the latest posts on our own, as we'd only get the
// first 20 posts otherwise.
if len(item.PostStream.Stream) > 20 {
p.TotalReplies = len(item.PostStream.Stream)
if p.TotalReplies > 20 {
if p.CurrentRepliesStartIDX == -1 ||
// Explain to me standard GoFmt logic:
p.CurrentRepliesStartIDX > (p.TotalReplies-20) {
p.CurrentRepliesStartIDX = (p.TotalReplies - 20)
// /)_-)
}
var postIDs []int
if p.CurrentRepliesStartIDX > 0 {
postIDs = append(postIDs,
item.PostStream.Stream[0])
p.CurrentRepliesStartIDX++
}
postIDs = append(postIDs,
item.PostStream.Stream[p.CurrentRepliesStartIDX:]...)
replies, err := sys.client.Topics.ShowPosts(
context.Background(),
p.ID,
item.PostStream.Stream[len(item.PostStream.Stream)-20:],
postIDs,
)
if err != nil {
sys.logger.Error(err)