this post was submitted on 24 Jun 2023
1 points (100.0% liked)

Lemmy App Development

693 readers
1 users here now

A place for Lemmy builders to chat about building apps, clients, tools and bots for the Lemmy platform.

On-Topic:

Off-Topic:

founded 1 year ago
MODERATORS
 

i have requests to fetch comment and post data, but i'm struggling to work out how to build a tree from the responses? do i fetch comments with arg parent_id to get a comment's children, and do so recursively for those comments returned that themselves have comments?

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 2 points 1 year ago

Pretty late to the party here, but I have an answer for you. There another parameter called "depth", you have to set that to "1" on the initial call. Then you only get "root" comments. Then, for each root comment, you call the API again with the parent id of said comment with the "depth" parameter set to depth+1 until there are no more comments.

So basically, you have to use recursion. If you want I can give you a code example from my App.