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

Comments with PostID not filtered by given post ID #1

Closed
mrusme opened this issue Dec 31, 2022 · 17 comments
Closed

Comments with PostID not filtered by given post ID #1

mrusme opened this issue Dec 31, 2022 · 17 comments
Labels
bug Something isn't working

Comments

@mrusme
Copy link

mrusme commented Dec 31, 2022

I'm trying to retrieve all comments for a specific post, hence I've been trying out different sorts of variations of this code:

	resp, err := sys.client.Comments(context.Background(), types.GetComments{
		Type: types.NewOptional(types.ListingLocal),
		Sort: types.NewOptional(types.CommentSortHot),
		// CommunityID: types.NewOptional(cid),
		PostID: types.NewOptional(pid),
	})

The pid is the correct post ID, yet the comments that I'm getting back seem to be simply the listing of all new local comments. I'm not quite sure what's going on there as it seems to me that changing different parameters won't alter the server's response in any way.

Maybe you might have idea of what's going on? I might very well just be holding it wrong.

mrusme added a commit to mrusme/neonmodem that referenced this issue Dec 31, 2022
@Elara6331
Copy link
Owner

Sorry for the late response, it was new year and I didn't have much time. I'll try to figure out what's going on here and get back to you, thanks.

@Elara6331 Elara6331 added the bug Something isn't working label Jan 2, 2023
@Elara6331
Copy link
Owner

Interestingly, it is sending post_id=458247 (I'm using post ID 458247 for testing) to the server, but it seems that's ignored for some reason.

@Elara6331
Copy link
Owner

The way Lemmy's UI seems to do it is they use getPost() and then check the comments field that's returned, but the Rust and JS structs don't have a comments field, so I'm not sure how that gets returned.

@mrusme
Copy link
Author

mrusme commented Jan 4, 2023

Maybe @dessalines might be able to help here? Would be cool to get this working, currently having a new Lemmy client in the works and this library saved my poor ass from having to implement all this on my own. :-)

Specifically, quote:

sending post_id=458247 (I'm using post ID 458247 for testing) to the server, but it seems that's ignored for some reason.

@dessalines
Copy link

dessalines commented Jan 5, 2023

https://join-lemmy.org/api/classes/LemmyHttp.html#getPost

@Arsen6331 the current main of lemmy / lemmy-js-client has a lot of API changes that haven't been deployed yet.

@Elara6331
Copy link
Owner

Elara6331 commented Jan 5, 2023

join-lemmy.org/api/classes/LemmyHttp.html#getPost

@Arsen6331 the current main of lemmy / lemmy-js-client has a lot of API changes that haven't been deployed yet.

I looked at the LemmyHttp docs, and neither getPost nor getPosts appear to return comments.

image

@dessalines
Copy link

dessalines commented Jan 5, 2023

Ah my bad, that must be showing the RC unfortunately.

Here you go:

https://github.com/LemmyNet/lemmy-js-client/blob/0.16.4/src/interfaces/api/post.ts#L29

LemmyNet/joinlemmy-site#123

@Elara6331
Copy link
Owner

Elara6331 commented Jan 5, 2023

The conversion done for this library is only partially automated, so if the API changes this much, it's going to become very difficult to maintain very quickly. To solve that, I'm working on a completely automated converter right now that I will use to automatically generate bindings for the latest release once it's done (should be pretty soon).

@mrusme
Copy link
Author

mrusme commented Jan 5, 2023

Is there a quickfix that can be used up until then however?

@Elara6331
Copy link
Owner

You can try adding a comments field to the GetPostResponse struct, but there are likely other issues you'll encounter.

@Elara6331
Copy link
Owner

Elara6331 commented Jan 5, 2023

The bindings are now completely automatically generated for v0.16.7. Can you try them and see if it fixes your issue? @mrusme

The Login() function has been renamed to ClientLogin(),

You have to use Post(), which will return GetPostResponse, which will have the comments, because that's the way the current API does it.

@mrusme
Copy link
Author

mrusme commented Jan 5, 2023

@Arsen6331 it seems that now types (e.g. ListingTypeSubscribe) are a bit messed up:

cannot use types.NewOptional(types.ListingTypeSubscribed) (value of type types.Optional[string]) as type types.Optional[types.ListingType] in struct literal

@Elara6331
Copy link
Owner

Ah, I forgot to use the type I created. Can you try now? It should be fixed.

@mrusme
Copy link
Author

mrusme commented Jan 5, 2023

Are you sure go.arsenm.dev/go-lemmy is updating properly? I can see your commits here but I'm using the package as it was defined in its go mod. Updated, checking.

@mrusme
Copy link
Author

mrusme commented Jan 5, 2023

It seems the internal time.Time parsing doesn't work yet:

parsing time "\"2022-12-29T01:39:01.346720\"" as "\"2006-01-02T15:04:05Z07:00\"": cannot parse "\"" as "Z07:00"

That's what I'm doing:

	resp, err := sys.client.Posts(context.Background(), types.GetPosts{
		Type:  types.NewOptional(types.ListingTypeSubscribed),
		Sort:  types.NewOptional(types.SortTypeNew),
		Limit: types.NewOptional(int64(50)),
	})

@Elara6331
Copy link
Owner

Just fixed that, should be working now

@mrusme
Copy link
Author

mrusme commented Jan 5, 2023

Awesome work! Can retrieve the correct comments now. 👍🏼 Very nice, thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants