-
-
Notifications
You must be signed in to change notification settings - Fork 42
Refactor role handling: Introduce JsonPartialRole and PartialRole for improved deserialization #413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jedrek0429
wants to merge
9
commits into
NetCordDev:main
Choose a base branch
from
jedrek0429:fix-invite-roles-deserialisation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
97255b3
Refactor role handling: Introduce JsonPartialRole and IPartialRole in…
jedrek0429 82e145a
Reduce unnecessary abstraction and make Role inherit directly from Pa…
jedrek0429 f48c940
Fix PartialRole initialisation arguments, constructor argument wrong …
jedrek0429 841eeea
Add GuildId property on PartialRole, and universalise xml comments fo…
jedrek0429 5dc038c
Add generated aliases for PartialRole
jedrek0429 2715e06
Fix type name override for PartialRole aliases, and cosmetic
jedrek0429 088f03a
Remove duplicate GenerateAlias for Role
jedrek0429 705f638
Merge branch 'NetCordDev:main' into fix-invite-roles-deserialisation
jedrek0429 483fc49
Remove deprecated field from JsonPartialRole and PartialRole, remove …
jedrek0429 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| using System.ComponentModel; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace NetCord.JsonModels; | ||
|
|
||
| /// <remarks> | ||
| /// This class is used when a role is returned in a context where not all properties are available, i.e. in <see cref="Rest.RestInvite"/>. | ||
| /// </remarks> | ||
| public class JsonPartialRole : JsonEntity | ||
| { | ||
| [JsonPropertyName("name")] | ||
| public string Name { get; set; } | ||
|
|
||
| [JsonPropertyName("position")] | ||
| public int Position { get; set; } | ||
|
|
||
| [JsonPropertyName("colors")] | ||
| public JsonRoleColors Colors { get; set; } | ||
|
|
||
| [JsonPropertyName("icon")] | ||
| public string? IconHash { get; set; } | ||
|
|
||
| [JsonPropertyName("unicode_emoji")] | ||
| public string? UnicodeEmoji { get; set; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| using System.ComponentModel; | ||
|
|
||
| using NetCord.JsonModels; | ||
| using NetCord.Rest; | ||
|
|
||
| namespace NetCord; | ||
|
|
||
| /// <summary> | ||
| /// Represents a partial role. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Useful for <see cref="Rest.RestInvite"/>. | ||
| /// </remarks> | ||
| public partial class PartialRole : ClientEntity, IJsonModel<JsonPartialRole> | ||
| { | ||
| JsonPartialRole IJsonModel<JsonPartialRole>.JsonModel => _jsonModel; | ||
| private readonly JsonPartialRole _jsonModel; | ||
|
|
||
| /// <summary> | ||
| /// The role's ID. | ||
| /// </summary> | ||
| public override ulong Id => _jsonModel.Id; | ||
|
|
||
| /// <summary> | ||
| /// The name of the role. | ||
| /// </summary> | ||
| public string Name => _jsonModel.Name; | ||
|
|
||
| /// <summary> | ||
| /// The role's colors. | ||
| /// </summary> | ||
| public RoleColors Colors { get; } | ||
|
|
||
| /// <summary> | ||
| /// The raw position of this role. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Use <see cref="Position"/> to get a properly comparable and sortable position value. | ||
| /// </remarks> | ||
| public int RawPosition => _jsonModel.Position; | ||
|
|
||
| /// <summary> | ||
| /// The position of this role for sorting and comparing. | ||
| /// </summary> | ||
| public RolePosition Position => new(RawPosition, Id); | ||
|
|
||
| /// <summary> | ||
| /// The role's icon hash. | ||
| /// </summary> | ||
| public string? IconHash => _jsonModel.IconHash; | ||
|
|
||
| /// <summary> | ||
| /// The role's Unicode emoji. | ||
| /// </summary> | ||
| public string? UnicodeEmoji => _jsonModel.UnicodeEmoji; | ||
|
|
||
| /// <summary> | ||
| /// The ID of the guild this role belongs to. | ||
| /// </summary> | ||
| public ulong GuildId { get; } | ||
|
|
||
| public override string ToString() => $"<@&{Id}>"; | ||
|
|
||
| public PartialRole(JsonPartialRole jsonModel, ulong guildId, RestClient client) : base(client) | ||
| { | ||
| _jsonModel = jsonModel; | ||
|
|
||
| Colors = new(jsonModel.Colors); | ||
|
|
||
| GuildId = guildId; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.