Skip to content

Commit 834344d

Browse files
committed
Added sticky parameter to distinguish, added comment sorting to post GetComments and GetCommentsWithMore, and fixed distinguish
1 parent b15a4c1 commit 834344d

File tree

3 files changed

+60
-20
lines changed

3 files changed

+60
-20
lines changed

RedditSharp/Things/ModeratableThing.cs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public enum DistinguishType
135135
[JsonProperty("user_reports")]
136136
[JsonConverter(typeof(ReportCollectionConverter))]
137137
public ICollection<Report> UserReports { get; private set; }
138-
138+
139139
/// <summary>
140140
/// Reports someone
141141
/// </summary>
@@ -174,7 +174,8 @@ public async Task ReportAsync(ReportType reportType, string otherReason = null)
174174
/// Distinguishes (or undistinguishes) an item
175175
/// </summary>
176176
/// <param name="distinguishType">Type you want to distinguish <see cref="DistinguishType"/></param>
177-
public async Task DistinguishAsync(DistinguishType distinguishType)
177+
/// <param name="sticky">Stickies the Thing if applicable</param>
178+
public async Task DistinguishAsync(DistinguishType distinguishType, bool sticky = false)
178179
{
179180

180181
string how;
@@ -196,7 +197,8 @@ public async Task DistinguishAsync(DistinguishType distinguishType)
196197
var json = await WebAgent.Post(DistinguishUrl, new
197198
{
198199
how,
199-
id = Id
200+
id = FullName, //oAuth requires the full ID
201+
sticky = sticky
200202
}).ConfigureAwait(false);
201203
if (json["jquery"].Count(i => i[0].Value<int>() == 11 && i[1].Value<int>() == 12) == 0)
202204
throw new Exception("You are not permitted to distinguish this comment.");
@@ -229,7 +231,7 @@ public Task RemoveSpamAsync()
229231
return RemoveImplAsync(true);
230232
}
231233

232-
#pragma warning disable 1591
234+
#pragma warning disable 1591
233235
protected async Task RemoveImplAsync(bool spam)
234236
{
235237
await WebAgent.Post(RemoveUrl, new
@@ -238,7 +240,7 @@ protected async Task RemoveImplAsync(bool spam)
238240
spam = spam
239241
}).ConfigureAwait(false);
240242
}
241-
#pragma warning restore 1591
243+
#pragma warning restore 1591
242244

243245
/// <summary>
244246
/// Delete this item.
@@ -276,8 +278,10 @@ public Task UnIgnoreReportsAsync()
276278
/// <param name="agent"><see cref="IWebAgent"/> used to send post</param>
277279
/// <param name="fullname">FullName of thing to act on. eg. t1_66666</param>
278280
/// <returns></returns>
279-
public static Task RemoveAsync( IWebAgent agent, string fullname ) {
280-
return agent.Post(RemoveUrl, new {
281+
public static Task RemoveAsync(IWebAgent agent, string fullname)
282+
{
283+
return agent.Post(RemoveUrl, new
284+
{
281285
id = fullname,
282286
spam = false
283287
});
@@ -289,8 +293,10 @@ public static Task RemoveAsync( IWebAgent agent, string fullname ) {
289293
/// <param name="agent"><see cref="IWebAgent"/> used to send post</param>
290294
/// <param name="fullname">FullName of thing to act on. eg. t1_66666</param>
291295
/// <returns></returns>
292-
public static Task SpamAsync( IWebAgent agent, string fullname ) {
293-
return agent.Post(RemoveUrl, new {
296+
public static Task SpamAsync(IWebAgent agent, string fullname)
297+
{
298+
return agent.Post(RemoveUrl, new
299+
{
294300
id = fullname,
295301
spam = true
296302
});
@@ -301,7 +307,8 @@ public static Task SpamAsync( IWebAgent agent, string fullname ) {
301307
/// <param name="agent"><see cref="IWebAgent"/> used to send post</param>
302308
/// <param name="fullname">FullName of thing to act on. eg. t1_66666</param>
303309
/// <returns></returns>
304-
public static Task ApproveAsync( IWebAgent agent, string fullname ) {
310+
public static Task ApproveAsync(IWebAgent agent, string fullname)
311+
{
305312
return Thing.SimpleActionAsync(agent, fullname, ApproveUrl);
306313
}
307314

@@ -312,10 +319,12 @@ public static Task ApproveAsync( IWebAgent agent, string fullname ) {
312319
/// <param name="otherReason">If your reason is "Other", say why you're reporting them</param>
313320
/// <param name="agent"><see cref="IWebAgent"/> used to send post</param>
314321
/// <param name="fullname">FullName of thing to act on. eg. t1_66666</param>
315-
public static Task ReportAsync( IWebAgent agent, string fullname, ReportType reportType, string otherReason = null ) {
322+
public static Task ReportAsync(IWebAgent agent, string fullname, ReportType reportType, string otherReason = null)
323+
{
316324

317325
string reportReason;
318-
switch(reportType) {
326+
switch (reportType)
327+
{
319328
case ReportType.Spam:
320329
reportReason = "spam"; break;
321330
case ReportType.VoteManipulation:
@@ -330,7 +339,8 @@ public static Task ReportAsync( IWebAgent agent, string fullname, ReportType rep
330339
reportReason = "other"; break;
331340
}
332341

333-
return agent.Post(ReportUrl, new {
342+
return agent.Post(ReportUrl, new
343+
{
334344
api_type = "json",
335345
reason = reportReason,
336346
other_reason = otherReason ?? "",

RedditSharp/Things/Post.cs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,25 @@ public async Task SetFlairAsync(string flairText, string flairClass)
225225
/// </summary>
226226
/// <param name="limit">Maximum number of comments to return</param>
227227
/// <returns></returns>
228-
public async Task<List<Comment>> GetCommentsAsync(int limit = 0)
228+
public async Task<List<Comment>> GetCommentsAsync(int limit = 0, CommentSort sort = CommentSort.Best)
229229
{
230230
var url = string.Format(GetCommentsUrl, Id);
231+
232+
//Only 'best' comment sorting isn't named the same
233+
if (sort == CommentSort.Best)
234+
{
235+
url = $"{url}?sort=confidence";
236+
}
237+
else
238+
{
239+
url = $"{url}?sort={sort.ToString().ToLower()}";
240+
}
241+
231242
if (limit > 0)
232243
{
233-
var query = "limit=" + limit;
234-
url = string.Format("{0}?{1}", url, query);
244+
url = $"{url}&limit={limit}";
235245
}
246+
236247
var json = await WebAgent.Get(url).ConfigureAwait(false);
237248
var postJson = json.Last()["data"]["children"];
238249

@@ -252,14 +263,25 @@ public async Task<List<Comment>> GetCommentsAsync(int limit = 0)
252263
/// </summary>
253264
/// <param name="limit">Maximum number of comments to return. Returned list may be larger than this number though due to <see cref="More"/></param>
254265
/// <returns></returns>
255-
public async Task<List<Thing>> GetCommentsWithMoresAsync(int limit = 0)
266+
public async Task<List<Thing>> GetCommentsWithMoresAsync(int limit = 0, CommentSort sort = CommentSort.Best)
256267
{
257268
var url = string.Format(GetCommentsUrl, Id);
269+
270+
//Only 'best' comment sorting isn't named the same
271+
if (sort == CommentSort.Best)
272+
{
273+
url = $"{url}?sort=confidence";
274+
}
275+
else
276+
{
277+
url = $"{url}?sort={sort.ToString().ToLower()}";
278+
}
279+
258280
if (limit > 0)
259281
{
260-
var query = "limit=" + limit;
261-
url = string.Format("{0}?{1}", url, query);
282+
url = $"{url}&limit={limit}";
262283
}
284+
263285
var json = await WebAgent.Get(url).ConfigureAwait(false);
264286
var postJson = json.Last()["data"]["children"];
265287

RedditSharp/Things/RedditUser.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,15 @@ public enum Sort
234234
Top,
235235
Controversial
236236
}
237-
237+
public enum CommentSort
238+
{
239+
Best,
240+
Top,
241+
New,
242+
Controversial,
243+
Old,
244+
Qa
245+
}
238246
public enum FromTime
239247
{
240248
All,

0 commit comments

Comments
 (0)