From 403343617540f6180908679665e1c0e7ed96cbf5 Mon Sep 17 00:00:00 2001 From: 178inaba <178inaba@users.noreply.github.com> Date: Mon, 8 May 2017 13:44:49 +0900 Subject: [PATCH] Fix to set MaxID and SinceID to exclusive --- cmd/mstdn/cmd_followers.go | 1 - mastodon.go | 7 +++---- mastodon_test.go | 17 +++++++++++++++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/cmd/mstdn/cmd_followers.go b/cmd/mstdn/cmd_followers.go index 9c99dbe..ecb4a79 100644 --- a/cmd/mstdn/cmd_followers.go +++ b/cmd/mstdn/cmd_followers.go @@ -28,7 +28,6 @@ func cmdFollowers(c *cli.Context) error { if pg.MaxID == 0 { break } - pg.SinceID = 0 time.Sleep(10 * time.Second) } s := newScreen(config) diff --git a/mastodon.go b/mastodon.go index 1729597..240833d 100644 --- a/mastodon.go +++ b/mastodon.go @@ -263,13 +263,12 @@ func (p *Pagination) toValues() url.Values { } func (p *Pagination) setValues(params url.Values) url.Values { - if p.MaxID != 0 { + if p.MaxID > 0 { params.Set("max_id", fmt.Sprint(p.MaxID)) - } - if p.SinceID != 0 { + } else if p.SinceID > 0 { params.Set("since_id", fmt.Sprint(p.SinceID)) } - if p.Limit != 0 { + if p.Limit > 0 { params.Set("limit", fmt.Sprint(p.Limit)) } diff --git a/mastodon_test.go b/mastodon_test.go index eac42cd..eb6c476 100644 --- a/mastodon_test.go +++ b/mastodon_test.go @@ -339,10 +339,23 @@ func TestPaginationSetValues(t *testing.T) { if after.Get("max_id") != "123" { t.Fatalf("want %q but %q", "123", after.Get("max_id")) } - if after.Get("since_id") != "789" { - t.Fatalf("want %q but %q", "789", after.Get("since_id")) + if after.Get("since_id") != "" { + t.Fatalf("result should be empty string: %q", after.Get("since_id")) } if after.Get("limit") != "10" { t.Fatalf("want %q but %q", "10", after.Get("limit")) } + + p = &Pagination{ + MaxID: 0, + SinceID: 789, + } + before = url.Values{} + after = p.setValues(before) + if after.Get("max_id") != "" { + t.Fatalf("result should be empty string: %q", after.Get("max_id")) + } + if after.Get("since_id") != "789" { + t.Fatalf("want %q but %q", "789", after.Get("since_id")) + } }