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 ( import (
"context" "context"
"fmt" "fmt"
"time"
"github.com/mattn/go-mastodon" "github.com/mattn/go-mastodon"
"github.com/urfave/cli" "github.com/urfave/cli"
@ -16,9 +17,20 @@ func cmdFollowers(c *cli.Context) error {
if err != nil { if err != nil {
return err return err
} }
followers, err := client.GetAccountFollowers(context.Background(), account.ID) var maxID *int64
if err != nil { var followers []*mastodon.Account
return err 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) s := newScreen(config)
for _, follower := range followers { for _, follower := range followers {

View File

@ -17,6 +17,7 @@ func TestCmdFollowers(t *testing.T) {
fmt.Fprintln(w, `{"id": 123}`) fmt.Fprintln(w, `{"id": 123}`)
return return
case "/api/v1/accounts/123/followers": 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"}]`) fmt.Fprintln(w, `[{"id": 234, "username": "ZZZ", "acct": "zzz"}]`)
return return
} }

View File

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

View File

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