Skip to content

Commit 7463d86

Browse files
authored
#219 - update to account for "more" in comment response. (#224)
1 parent 07e1d8a commit 7463d86

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

RedditSharp/Things/Comment.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,17 @@ private void ParseComments(JToken data, Thing sender)
102102
if (replies != null && replies.Count() > 0)
103103
{
104104
foreach (var comment in replies["data"]["children"])
105-
subComments.Add(new Comment(WebAgent, comment, sender));
105+
{
106+
if (comment.Value<string>("kind") != "more")
107+
{
108+
subComments.Add(new Comment(WebAgent, comment, sender));
109+
}
110+
else
111+
{
112+
More = (new More(WebAgent, comment));
113+
}
114+
115+
}
106116
}
107117
Comments = subComments.ToArray();
108118
}

RedditSharp/Things/Post.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public async Task<List<Comment>> GetCommentsAsync(int limit = 0, CommentSort sor
288288
/// </summary>
289289
/// <param name="limit">Maximum number of comments to return. Returned list may be larger than this number though due to <see cref="More"/></param>
290290
/// <returns></returns>
291-
public async Task<List<Thing>> GetCommentsWithMoresAsync(int limit = 0, CommentSort sort = CommentSort.Best)
291+
public async Task<List<Thing>> GetCommentsWithMoresAsync(int limit = 0, CommentSort sort = CommentSort.Best, int depth=0)
292292
{
293293
var url = string.Format(GetCommentsUrl, Id);
294294

@@ -307,6 +307,11 @@ public async Task<List<Thing>> GetCommentsWithMoresAsync(int limit = 0, CommentS
307307
url = $"{url}&limit={limit}";
308308
}
309309

310+
if(depth > 0)
311+
{
312+
url = $"{url}&depth={depth}";
313+
}
314+
310315
var json = await WebAgent.Get(url).ConfigureAwait(false);
311316
var postJson = json.Last()["data"]["children"];
312317

RedditSharpTests/Things/PostTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,22 @@ public async Task GetCommentsMore()
4242
Assert.Equal(10, comments.Count);
4343

4444
}
45+
[Fact]
46+
public async Task GetCommentsWithMoresAsync()
47+
{
48+
RedditSharp.WebAgent agent = new RedditSharp.WebAgent(authFixture.AccessToken);
49+
RedditSharp.Reddit reddit = new RedditSharp.Reddit(agent);
50+
var post = (Post)await reddit.GetThingByFullnameAsync("t3_f1bo6u");
51+
52+
var things = await post.GetCommentsWithMoresAsync(limit: 9, depth: 2);
53+
Assert.NotEmpty(things);
54+
Assert.Equal(typeof(More), things.Last().GetType());
55+
Assert.NotNull(((Comment)things[0]).More);
56+
Assert.NotNull(((Comment)things[0]).Comments[0].More);
57+
58+
}
59+
60+
4561

4662
[Fact]
4763
public async Task EnumerateAllComments()
@@ -59,5 +75,7 @@ public async Task EnumerateAllComments()
5975
Assert.Equal(25, commentsList.Count);
6076

6177
}
78+
79+
6280
}
6381
}

0 commit comments

Comments
 (0)