ref: 5b66b4096e7b1cdb74580da41597d69fb93123a1
dir: /status.go/
package main
import (
"context"
"fmt"
mastodon "codeberg.org/penny64/hellclient-go-mastodon"
)
const maxUnreadStatusesToLoad = 30
func (hc *Hellclient) GetStatusesSince(ID mastodon.ID, GetTimeline func(ctx context.Context, pg *mastodon.Pagination) ([]*mastodon.Status, error)) ([]*mastodon.Status, error) {
page := &mastodon.Pagination{MinID: ID, Limit: 40}
var err error
var statuses []*mastodon.Status
for {
var statusbatch []*mastodon.Status
statusfunc := func(job *GenericJob) { statusbatch, err = GetTimeline(context.Background(), page) }
statusjob := hc.dispatchFunc(statusfunc)
statusjob.Wait()
if err != nil {
return statuses, err
}
if len(statusbatch) == 0 {
break
}
for i := len(statusbatch) - 1; i >= 0; i-- {
statuses = append(statuses, statusbatch[i])
}
//I really don't understand the server's results but erase the max ID and it paginates up I don't know man
page.MaxID = ""
fmt.Printf("Loaded %v statuses....", len(statuses))
if len(statuses) >= maxUnreadStatusesToLoad {
break
}
//We ask for 40 results, if there were less than 40, there's no more to load
if len(statusbatch) < 40 {
break
}
}
return statuses, err
}