Fix pagination for mstdn command

pull/54/head
178inaba 2017-05-05 00:18:17 +09:00
parent 5fad354d1a
commit dd0b467062
4 changed files with 18 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"time"
"github.com/mattn/go-mastodon"
"github.com/urfave/cli"
@ -16,9 +17,20 @@ func cmdFollowers(c *cli.Context) error {
if err != nil {
return err
}
followers, err := client.GetAccountFollowers(context.Background(), account.ID)
if err != nil {
return err
var maxID *int64
var followers []*mastodon.Account
for {
fs, pg, err := client.GetAccountFollowers(
context.Background(), account.ID, &mastodon.Pagination{MaxID: maxID})
if err != nil {
return err
}
followers = append(followers, fs...)
if pg.MaxID == nil {
break
}
maxID = pg.MaxID
time.Sleep(10 * time.Second)
}
s := newScreen(config)
for _, follower := range followers {

View File

@ -17,6 +17,7 @@ func TestCmdFollowers(t *testing.T) {
fmt.Fprintln(w, `{"id": 123}`)
return
case "/api/v1/accounts/123/followers":
w.Header().Set("Link", `<http://example.com?since_id=890>; rel="prev"`)
fmt.Fprintln(w, `[{"id": 234, "username": "ZZZ", "acct": "zzz"}]`)
return
}

View File

@ -11,7 +11,7 @@ import (
func cmdNotification(c *cli.Context) error {
client := c.App.Metadata["client"].(*mastodon.Client)
notifications, err := client.GetNotifications(context.Background())
notifications, _, err := client.GetNotifications(context.Background(), nil)
if err != nil {
return err
}

View File

@ -10,7 +10,7 @@ import (
func cmdTimeline(c *cli.Context) error {
client := c.App.Metadata["client"].(*mastodon.Client)
config := c.App.Metadata["config"].(*mastodon.Config)
timeline, err := client.GetTimelineHome(context.Background())
timeline, _, err := client.GetTimelineHome(context.Background(), nil)
if err != nil {
return err
}