Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination not working with GetTimelinePublic and Mastodon 2.6.5 #86

Closed
marians opened this issue Dec 21, 2018 · 8 comments
Closed

Pagination not working with GetTimelinePublic and Mastodon 2.6.5 #86

marians opened this issue Dec 21, 2018 · 8 comments

Comments

@marians
Copy link
Contributor

marians commented Dec 21, 2018

I tried using go-mastodon against the https://chaos.social instance, which uses version 2.6.5 according to https://chaos.social/api/v1/instance, with following code:

package main

import (
	"context"
	"fmt"
	"log"
	"time"

	"github.com/mattn/go-mastodon"
)

func main() {
	ctx := context.Background()

	c := mastodon.NewClient(&mastodon.Config{
		Server: "https://chaos.social",
	})

	pg := mastodon.Pagination{}

	for {
		timeline, err := c.GetTimelinePublic(ctx, false, &pg)
		if err != nil {
			log.Println(err)
		}

		for _, item := range timeline {
			fmt.Printf("%#v\n", item)
		}

		if pg.MaxID == "" {
			break
		}

		time.Sleep(10 * time.Second)
	}
}

This quits with the output

2018/12/21 07:25:04 strconv.ParseInt: parsing "": invalid syntax

which is coming from

id, err := strconv.ParseInt(val, 10, 64)

I have an experimental fix that works for me here for the simple purpose of the above code: https://github.com/marians/go-mastodon/pull/1/files

My understanding of the Mastodon API version differences is not deep enough to tell when min_id has been introduced, where it is used, whether since_id is still in use etc. So I can't provide a PR currently that makes pagination work in all cases. Hopefully the description is enough for others to do so. Thanks!

@mattn
Copy link
Owner

mattn commented Dec 21, 2018

@178inaba Can you handle this issue?

@178inaba
Copy link
Contributor

@mattn OK!

@178inaba
Copy link
Contributor

178inaba commented Dec 26, 2018

I confirmed the following response in the Link header.

<https://chaos.social/api/v1/timelines/public?max_id=101306164022079793>; rel="next", <https://chaos.social/api/v1/timelines/public?min_id=101306170504618280>; rel="prev"

It seems that this change came in at 2.6.0.
https://github.com/tootsuite/mastodon/releases/tag/v2.6.0

Support backwards pagination (#8736)

The new pagination param min_id is the symmetrical opposite of max_id, i.e. it can be used for stepwise pagination from older to newer statuses. The difference to since_id is that since_id will always return the latest statuses, just merely cut off by the provided ID. The new param is supported on all API methods that return statuses.

I will show my recognition as an example.

For example, suppose you have a status ID like the one below.
1, 2, 3 ... 98, 99, 100

In this case, the response should be as follows.
/api/v1/timelines/public?min_id=1&limit=5 -> 2, 3, 4, 5, 6
/api/v1/timelines/public?since_id=1&limit=5 -> 96, 97, 98, 99, 100
/api/v1/timelines/public?since_id=97 -> 98, 99, 100
/api/v1/timelines/public?since_id=50&max_id=54 -> 51, 52, 53

since_id is still in use, but I think that the Link header should be modified since it uses min_id.

@marians Can you submit your pull request to this repository?

@marians
Copy link
Contributor Author

marians commented Dec 26, 2018

@178inaba I'd rather not do that. Because (a) the change is trivial and (b) according to my understanding, especially from your comment, this will break pagination for servers < 2.6.0.

@178inaba
Copy link
Contributor

178inaba commented Jan 9, 2019

@marians Thank you.
I will consider how to fix it.

@178inaba
Copy link
Contributor

@marians I am sorry to be late.
I fixed it with #90 !
Please check it!

@marians
Copy link
Contributor Author

marians commented Feb 15, 2019

Thanks! Not sure when I'll be able to test this. Will close for now.

@marians marians closed this as completed Feb 15, 2019
@mattn
Copy link
Owner

mattn commented Feb 15, 2019

@178inaba Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants