mirror of
https://github.com/mrusme/neonmodem.git
synced 2024-09-22 04:35:55 -04:00
Implemented reply chunks querying for #10
This commit is contained in:
parent
a4e4db91b7
commit
51cb1d971b
@ -28,7 +28,9 @@ type Post struct {
|
|||||||
|
|
||||||
Forum forum.Forum
|
Forum forum.Forum
|
||||||
|
|
||||||
Replies []reply.Reply
|
TotalReplies int
|
||||||
|
CurrentRepliesStartIDX int
|
||||||
|
Replies []reply.Reply
|
||||||
|
|
||||||
URL string
|
URL string
|
||||||
|
|
||||||
|
@ -236,6 +236,9 @@ func (sys *System) ListPosts(forumID string) ([]post.Post, error) {
|
|||||||
SysIDX: sys.ID,
|
SysIDX: sys.ID,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
TotalReplies: 0,
|
||||||
|
CurrentRepliesStartIDX: -1,
|
||||||
|
|
||||||
URL: fmt.Sprintf("%s/t/%d", baseURL, i.ID),
|
URL: fmt.Sprintf("%s/t/%d", baseURL, i.ID),
|
||||||
|
|
||||||
SysIDX: sys.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
|
// 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
|
// posts, we need to fetch the latest posts on our own, as we'd only get the
|
||||||
// first 20 posts otherwise.
|
// 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(
|
replies, err := sys.client.Topics.ShowPosts(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
p.ID,
|
p.ID,
|
||||||
item.PostStream.Stream[len(item.PostStream.Stream)-20:],
|
postIDs,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
sys.logger.Error(err)
|
sys.logger.Error(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user