Getting more top-level (depth=0) post comments.
I have no problems getting the "first page" of post comments using the code below.
var post = reddit.Post(postId).About();
var comments = post.Comments.GetComments(sort: "best");
With the comments returned I can get more comments within comment trees (depth>0) using the code below.
var children = reddit.Models.LinksAndComments.MoreChildren(
new Reddit.Inputs.LinksAndComments.LinksAndCommentsMoreChildrenInput(linkId: postId, children: idString));
var mapped = _mapper.Map<List<RedditComment>>(children.Comments);
However, I'm stuck on how to get more top-level (depth=0) comments for the post as there is no "More" objects for the post.
Any direction you can give me on this would be appreciated.
The "More" functionality is broken in the current version. I've already fixed it on the develop branch and 1.4 will be released very soon.
I recommend you wait until the 1.4 release of Reddit.NET, then try again. If you still have problems, you can post again here and I'll help you out.
The more functionality now works.
However, the issue I'm having now is that when I fetch post comments the more children object only has a single extra comment id.
How I get post comments:
public async Task<List<RedditComment>> GetPostCommentsPaged(ClaimsPrincipal claim, string postId, string lastPostId)
{
var user = await _userService.GetCurrentUser(claim);
var reddit = await _redditManager.GetRedditInstance(user.RefreshToken, user.AccessToken);
var post = reddit.Post(postId).About();
var comments = post.Comments.GetComments(sort: "best");
var listings = comments.Select(x => x.Listing);
var mapped = _mapper.Map<List<RedditComment>>(listings);
return mapped;
}
This means when I use the MoreChildren feature I only get the extra comment because it is the only id I have.
How I get more children:
public async Task<List<RedditComment>> GetMoreComments(ClaimsPrincipal claim, string postId, List<string> commentIds)
{
var user = await _userService.GetCurrentUser(claim);
var reddit = await _redditManager.GetRedditInstance(user.RefreshToken, user.AccessToken);
var idString = string.Join(',', commentIds.Take(100));
var children = reddit.Models.LinksAndComments.MoreChildren(
new Reddit.Inputs.LinksAndComments.LinksAndCommentsMoreChildrenInput(linkId: postId, children: idString));
var mapped = _mapper.Map<List<RedditComment>>(children.Comments);
foreach (var item in mapped)
{
if (item.Replies == null)
item.Replies = new List<RedditComment>();
item.Replies.AddRange(
mapped.Where(x => x.ParentFullname == item.Fullname)
.OrderByDescending(x => x.Score)
.ThenByDescending(x => x.Created)
.ToList());
}
var minDepth = mapped.Select(x => x.Depth).Min();
var result = mapped.Where(x => x.Depth == minDepth).ToList();
return result;
}
Am I missing something?
I would caution against attempting to handle comment reply trees directly via the Models, as that can get really messy really fast. Instead, the Controllers optimize this and provide a simpler interface.
That said, I would suggest you post this new question over on r/redditdev, as it sounds like you're not getting as many MoreChildren ids from the API as you're expecting. Reddit.NET just passes along what the API gives it.