Skip to content

Commit d968ca9

Browse files
committed
Fix inheritance issues with VotableThing
1 parent ae344f9 commit d968ca9

File tree

5 files changed

+169
-292
lines changed

5 files changed

+169
-292
lines changed

RedditSharp/Things/Comment.cs

Lines changed: 3 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,7 @@ public class Comment : VotableThing
1515
{
1616
private const string CommentUrl = "/api/comment";
1717
private const string EditUserTextUrl = "/api/editusertext";
18-
private const string RemoveUrl = "/api/remove";
19-
private const string DelUrl = "/api/del";
20-
private const string ApproveUrl = "/api/approve";
2118
private const string SetAsReadUrl = "/api/read_message";
22-
private const string IgnoreReportsUrl = "/api/ignore_reports";
23-
private const string UnIgnoreReportsUrl = "/api/unignore_reports";
24-
25-
[JsonIgnore]
26-
private Reddit Reddit { get; set; }
27-
[JsonIgnore]
28-
private IWebAgent WebAgent { get; set; }
2919

3020
/// <summary>
3121
/// Initialize.
@@ -175,14 +165,9 @@ private async Task ParseCommentsAsync(Reddit reddit, JToken data, IWebAgent webA
175165
/// <summary>
176166
/// Comment author user name.
177167
/// </summary>
178-
[JsonProperty("author")]
179-
public string Author { get; set; }
180-
181-
/// <summary>
182-
/// Moderator this comment was removed by. Will be null or empty if the comment has not been removed.
183-
/// </summary>
184-
[JsonProperty("banned_by")]
185-
public string BannedBy { get; set; }
168+
[JsonIgnore]
169+
[Obsolete("Use AuthorName instead.", false)]
170+
public string Author => base.AuthorName;
186171

187172
/// <summary>
188173
/// Comment body markdown.
@@ -208,30 +193,6 @@ private async Task ParseCommentsAsync(Reddit reddit, JToken data, IWebAgent webA
208193
[JsonProperty("subreddit")]
209194
public string Subreddit { get; set; }
210195

211-
/// <summary>
212-
/// Moderator this comment was approved by. Will be null or empty if the comment has not been approved.
213-
/// </summary>
214-
[JsonProperty("approved_by")]
215-
public string ApprovedBy { get; set; }
216-
217-
/// <summary>
218-
/// Css class of the authors flair.
219-
/// </summary>
220-
[JsonProperty("author_flair_css_class")]
221-
public string AuthorFlairCssClass { get; set; }
222-
223-
/// <summary>
224-
/// Text of the authors flair.
225-
/// </summary>
226-
[JsonProperty("author_flair_text")]
227-
public string AuthorFlairText { get; set; }
228-
229-
/// <summary>
230-
/// Number of times this comment has been gilded.
231-
/// </summary>
232-
[JsonProperty("gilded")]
233-
public int Gilded { get; set; }
234-
235196
/// <summary>
236197
/// Link id.
237198
/// </summary>
@@ -244,18 +205,6 @@ private async Task ParseCommentsAsync(Reddit reddit, JToken data, IWebAgent webA
244205
[JsonProperty("link_title")]
245206
public string LinkTitle { get; set; }
246207

247-
/// <summary>
248-
/// Number of reports on this comment.
249-
/// </summary>
250-
[JsonProperty("num_reports")]
251-
public int? NumReports { get; set; }
252-
253-
/// <summary>
254-
/// Returns true if this comment is stickied.
255-
/// </summary>
256-
[JsonProperty("stickied")]
257-
public bool IsStickied { get; set; }
258-
259208
/// <summary>
260209
/// More comments.
261210
/// </summary>
@@ -355,55 +304,6 @@ public void EditText(string newText)
355304
throw new Exception("Error editing text.");
356305
}
357306

358-
/// <summary>
359-
/// Approve this comment. Logged in user must be a moderator of parent subreddit.
360-
/// </summary>
361-
public void Approve()
362-
{
363-
var data = SimpleAction(ApproveUrl);
364-
}
365-
366-
/// <summary>
367-
/// Delete this comment. Logged in user must be a moderator of parent subreddit.
368-
/// or the Author of this comment.
369-
/// </summary>
370-
public void Del()
371-
{
372-
var data = SimpleAction(DelUrl);
373-
}
374-
375-
/// <summary>
376-
/// Ignore reports on this comment. Logged in user must be a moderator of parent subreddit.
377-
/// </summary>
378-
public void IgnoreReports()
379-
{
380-
var data = SimpleAction(IgnoreReportsUrl);
381-
}
382-
383-
/// <summary>
384-
/// Unignore reports on this comment. Logged in user must be a moderator of parent subreddit.
385-
/// </summary>
386-
public void UnIgnoreReports()
387-
{
388-
var data = SimpleAction(UnIgnoreReportsUrl);
389-
}
390-
391-
/// <summary>
392-
/// Remove this comment. Logged in user must be a moderator of parent subreddit.
393-
/// </summary>
394-
public void Remove()
395-
{
396-
RemoveImpl(false);
397-
}
398-
399-
/// <summary>
400-
/// Remove this comment, flagging it as spam. Logged in user must be a moderator of parent subreddit.
401-
/// </summary>
402-
public void RemoveSpam()
403-
{
404-
RemoveImpl(true);
405-
}
406-
407307
/// <summary>
408308
/// Mark this comment as read.
409309
/// </summary>
@@ -419,37 +319,5 @@ public void SetAsRead()
419319
var response = request.GetResponse();
420320
var data = WebAgent.GetResponseString(response.GetResponseStream());
421321
}
422-
423-
private void RemoveImpl(bool spam)
424-
{
425-
var request = WebAgent.CreatePost(RemoveUrl);
426-
var stream = request.GetRequestStream();
427-
WebAgent.WritePostBody(stream, new
428-
{
429-
id = FullName,
430-
spam = spam,
431-
uh = Reddit.User.Modhash
432-
});
433-
stream.Close();
434-
var response = request.GetResponse();
435-
var data = WebAgent.GetResponseString(response.GetResponseStream());
436-
}
437-
438-
private string SimpleAction(string endpoint)
439-
{
440-
if (Reddit.User == null)
441-
throw new AuthenticationException("No user logged in.");
442-
var request = WebAgent.CreatePost(endpoint);
443-
var stream = request.GetRequestStream();
444-
WebAgent.WritePostBody(stream, new
445-
{
446-
id = FullName,
447-
uh = Reddit.User.Modhash
448-
});
449-
stream.Close();
450-
var response = request.GetResponse();
451-
var data = WebAgent.GetResponseString(response.GetResponseStream());
452-
return data;
453-
}
454322
}
455323
}

RedditSharp/Things/ModAction.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,6 @@ public Thing TargetThing
7878
}
7979
}
8080

81-
[JsonIgnore]
82-
private Reddit Reddit { get; set; }
83-
84-
[JsonIgnore]
85-
private IWebAgent WebAgent { get; set; }
86-
8781
/// <summary>
8882
/// Initialize
8983
/// </summary>

0 commit comments

Comments
 (0)