Skip to content

Commit 2fa8aab

Browse files
committed
Change inheritance so that ModeratorUser, BannedUser, Contributor all inherit from RelUser.
1 parent 251deb0 commit 2fa8aab

File tree

5 files changed

+31
-93
lines changed

5 files changed

+31
-93
lines changed
Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,23 @@
11
using Newtonsoft.Json;
22
using Newtonsoft.Json.Linq;
3+
using RedditSharp.Things.User;
34

45
namespace RedditSharp
56
{
67
/// <summary>
78
/// Represents a moderator.
89
/// </summary>
9-
public class ModeratorUser
10+
public class ModeratorUser : RelUser
1011
{
11-
/// <summary>
12-
/// Create ModeratorUser from given JSON
13-
/// </summary>
14-
/// <param name="json"></param>
15-
public ModeratorUser(JToken json)
16-
{
17-
Helpers.PopulateObject(json, this);
18-
}
12+
public ModeratorUser(IWebAgent agent, JToken json) : base(agent, json)
13+
{
14+
}
1915

20-
/// <summary>
21-
/// Moderator username.
22-
/// </summary>
23-
[JsonProperty("name")]
24-
public string Name { get; private set; }
25-
26-
/// <summary>
27-
/// base36 Id of the moderator.
28-
/// </summary>
29-
[JsonProperty("id")]
30-
public string Id { get; private set; }
31-
32-
/// <summary>
33-
/// Permissions the moderator has in the subreddit.
34-
/// </summary>
35-
[JsonProperty("mod_permissions")]
16+
/// <summary>
17+
/// Permissions the moderator has in the subreddit.
18+
/// </summary>
19+
[JsonProperty("mod_permissions")]
3620
[JsonConverter(typeof (ModeratorPermissionConverter))]
3721
public ModeratorPermission Permissions { get; private set; }
38-
39-
/// <inheritdoc/>
40-
public override string ToString()
41-
{
42-
return Name;
43-
}
4422
}
4523
}

RedditSharp/Things/BannedUser.cs

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,29 @@
11
using Newtonsoft.Json;
22
using Newtonsoft.Json.Linq;
3-
using RedditSharp.Extensions;
3+
using RedditSharp.Things.User;
44
using System;
55

66
namespace RedditSharp.Things
77
{
88
/// <summary>
99
/// A user that is banned in a subreddit.
1010
/// </summary>
11-
public class BannedUser : RedditUser
11+
public class BannedUser : RelUser
1212
{
1313
/// <inheritdoc />
1414
public BannedUser(IWebAgent agent, JToken json) : base(agent, json) {
15-
var data = json["name"] == null ? json["data"] : json;
16-
base.Name = data["name"].ValueOrDefault<string>();
17-
var id = data["id"].ValueOrDefault<string>();
18-
if (id.Contains("_"))
19-
{
20-
base.Kind = "t2";
21-
base.Id = id.Split('_')[1];
22-
base.FullName = id;
23-
}
2415
}
2516

2617
/// <summary>
2718
/// Date the user was banned.
2819
/// </summary>
29-
[JsonProperty("date")]
30-
[JsonConverter(typeof(UnixTimestampConverter))]
31-
public DateTime? BanDate { get; private set; }
20+
[Obsolete("User RelUser.Date")]
21+
public DateTime? BanDate { get => DateUTC; private set => DateUTC = value; }
3222

3323
/// <summary>
3424
/// Ban note.
3525
/// </summary>
3626
[JsonProperty("note")]
3727
public string Note { get; private set; }
38-
39-
/// <summary>
40-
/// This will always return 0 for BannedUsers
41-
/// </summary>
42-
[JsonIgnore]
43-
public new int CommentKarma => 0;
44-
45-
/// <summary>
46-
/// This will always return 0 for BannedUsers
47-
/// </summary>
48-
[JsonIgnore]
49-
public new int LinkKarma => 0;
5028
}
5129
}

RedditSharp/Things/Contributor.cs

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,23 @@
11
using Newtonsoft.Json;
22
using Newtonsoft.Json.Linq;
3-
using RedditSharp.Extensions;
3+
using RedditSharp.Things.User;
44
using System;
55

66
namespace RedditSharp.Things
77
{
88
/// <summary>
99
/// A contributor to a subreddit.
1010
/// </summary>
11-
public class Contributor : RedditUser
11+
public class Contributor : RelUser
1212
{
1313
/// <inheritdoc />
1414
public Contributor(IWebAgent agent, JToken json) : base(agent, json) {
15-
var data = json["name"] == null ? json["data"] : json;
16-
base.Name = data["name"].ValueOrDefault<string>();
17-
var id = data["id"].ValueOrDefault<string>();
18-
if (id.Contains("_"))
19-
{
20-
base.Id = id.Split('_')[1];
21-
base.FullName = id;
22-
}
2315
}
2416

25-
/// <summary>
26-
/// Contributor name.
27-
/// </summary>
28-
[JsonProperty("name")]
29-
public new string Name { get; private set; }
30-
31-
/// <summary>
32-
/// Date contributor was added.
33-
/// </summary>
34-
[JsonProperty("date")]
35-
[JsonConverter(typeof(UnixTimestampConverter))]
36-
public DateTime DateAdded { get; private set; }
37-
38-
/// <summary>
39-
/// This will always return 0 for Contributors
40-
/// </summary>
41-
[JsonIgnore]
42-
public new int CommentKarma => 0;
43-
44-
/// <summary>
45-
/// This will always return 0 for Contributors
46-
/// </summary>
47-
[JsonIgnore]
48-
public new int LinkKarma => 0;
49-
}
17+
/// <summary>
18+
/// Date contributor was added.
19+
/// </summary>
20+
[Obsolete("User RelUser.Date")]
21+
public DateTime? DateAdded { get => DateUTC; private set => DateUTC = value; }
22+
}
5023
}

RedditSharp/Things/Subreddit.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ public static async Task<IEnumerable<ModeratorUser>> GetModeratorsAsync(IWebAgen
950950
var mods = data["children"].ToArray();
951951
var result = new ModeratorUser[mods.Length];
952952
for(var i = 0; i < mods.Length; i++) {
953-
var mod = new ModeratorUser(mods[i]);
953+
var mod = new ModeratorUser(agent, mods[i]);
954954
result[i] = mod;
955955
}
956956
return result;

RedditSharp/Things/User/PartialUser.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Newtonsoft.Json;
22
using Newtonsoft.Json.Linq;
3+
using RedditSharp.Extensions;
34
using System;
45
using System.Threading.Tasks;
56

@@ -13,6 +14,14 @@ public class PartialUser : CreatedThing
1314
/// <inheritdoc />
1415
public PartialUser(IWebAgent agent, JToken json) : base(agent, json)
1516
{
17+
var data = json["name"] == null ? json["data"] : json;
18+
Name = data["name"].ValueOrDefault<string>();
19+
var id = data["id"].ValueOrDefault<string>();
20+
if (id.Contains("_"))
21+
{
22+
base.Id = id.Split('_')[1];
23+
base.FullName = id;
24+
}
1625
}
1726
#region Properties
1827
private string OverviewUrl => $"/user/{Name}.json";

0 commit comments

Comments
 (0)