Skip to content

Commit

Permalink
fix: Invite and InviteMetadata properties (#1639)
Browse files Browse the repository at this point in the history
* fixes #1495

* keep obsolete properties and return types for compatibility

* missing properties for SocketInvite

* Restore xml docs and change obsolete message

Co-authored-by: Paulo <pnmanjos@hotmail.com>
  • Loading branch information
Fyers and SubZero0 authored Dec 19, 2020
1 parent 36de7b2 commit dd2e524
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 34 deletions.
21 changes: 21 additions & 0 deletions src/Discord.Net.Core/Entities/Invites/IInvite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ public interface IInvite : IEntity<string>, IDeletable
/// </returns>
string Url { get; }

/// <summary>
/// Gets the user that created this invite.
/// </summary>
/// <returns>
/// A user that created this invite.
/// </returns>
IUser Inviter { get; }
/// <summary>
/// Gets the channel this invite is linked to.
/// </summary>
Expand Down Expand Up @@ -83,5 +90,19 @@ public interface IInvite : IEntity<string>, IDeletable
/// invite points to; <c>null</c> if one cannot be obtained.
/// </returns>
int? MemberCount { get; }
/// <summary>
/// Gets the user this invite is linked to via <see cref="TargetUserType"/>.
/// </summary>
/// <returns>
/// A user that is linked to this invite.
/// </returns>
IUser TargetUser { get; }
/// <summary>
/// Gets the type of the linked <see cref="TargetUser"/> for this invite.
/// </summary>
/// <returns>
/// The type of the linked user that is linked to this invite.
/// </returns>
TargetUserType TargetUserType { get; }
}
}
16 changes: 5 additions & 11 deletions src/Discord.Net.Core/Entities/Invites/IInviteMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,22 @@ namespace Discord
public interface IInviteMetadata : IInvite
{
/// <summary>
/// Gets the user that created this invite.
/// Gets a value that indicates whether the invite is a temporary one.
/// </summary>
/// <returns>
/// A user that created this invite.
/// <c>true</c> if users accepting this invite will be removed from the guild when they log off; otherwise
/// <c>false</c>.
/// </returns>
IUser Inviter { get; }
bool IsTemporary { get; }
/// <summary>
/// Gets a value that indicates whether the invite has been revoked.
/// </summary>
/// <returns>
/// <c>true</c> if this invite was revoked; otherwise <c>false</c>.
/// </returns>
[Obsolete("This property doesn't exist anymore and shouldn't be used.")]
bool IsRevoked { get; }
/// <summary>
/// Gets a value that indicates whether the invite is a temporary one.
/// </summary>
/// <returns>
/// <c>true</c> if users accepting this invite will be removed from the guild when they log off; otherwise
/// <c>false</c>.
/// </returns>
bool IsTemporary { get; }
/// <summary>
/// Gets the time (in seconds) until the invite expires.
/// </summary>
/// <returns>
Expand Down
6 changes: 6 additions & 0 deletions src/Discord.Net.Rest/API/Common/Invite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ internal class Invite
public Optional<InviteGuild> Guild { get; set; }
[JsonProperty("channel")]
public InviteChannel Channel { get; set; }
[JsonProperty("inviter")]
public Optional<User> Inviter { get; set; }
[JsonProperty("approximate_presence_count")]
public Optional<int?> PresenceCount { get; set; }
[JsonProperty("approximate_member_count")]
public Optional<int?> MemberCount { get; set; }
[JsonProperty("target_user")]
public Optional<User> TargetUser { get; set; }
[JsonProperty("target_user_type")]
public Optional<TargetUserType> TargetUserType { get; set; }
}
}
12 changes: 4 additions & 8 deletions src/Discord.Net.Rest/API/Common/InviteMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@ namespace Discord.API
{
internal class InviteMetadata : Invite
{
[JsonProperty("inviter")]
public User Inviter { get; set; }
[JsonProperty("uses")]
public Optional<int> Uses { get; set; }
public int Uses { get; set; }
[JsonProperty("max_uses")]
public Optional<int> MaxUses { get; set; }
public int MaxUses { get; set; }
[JsonProperty("max_age")]
public Optional<int> MaxAge { get; set; }
public int MaxAge { get; set; }
[JsonProperty("temporary")]
public bool Temporary { get; set; }
[JsonProperty("created_at")]
public Optional<DateTimeOffset> CreatedAt { get; set; }
[JsonProperty("revoked")]
public bool Revoked { get; set; }
public DateTimeOffset CreatedAt { get; set; }
}
}
9 changes: 9 additions & 0 deletions src/Discord.Net.Rest/Entities/Invites/RestInvite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public class RestInvite : RestEntity<string>, IInvite, IUpdateable
public ulong ChannelId { get; private set; }
/// <inheritdoc />
public ulong? GuildId { get; private set; }
/// <inheritdoc />
public IUser Inviter { get; private set; }
/// <inheritdoc />
public IUser TargetUser { get; private set; }
/// <inheritdoc />
public TargetUserType TargetUserType { get; private set; }
internal IChannel Channel { get; }
internal IGuild Guild { get; }

Expand Down Expand Up @@ -50,6 +56,9 @@ internal void Update(Model model)
MemberCount = model.MemberCount.IsSpecified ? model.MemberCount.Value : null;
PresenceCount = model.PresenceCount.IsSpecified ? model.PresenceCount.Value : null;
ChannelType = (ChannelType)model.Channel.Type;
Inviter = model.Inviter.IsSpecified ? RestUser.Create(Discord, model.Inviter.Value) : null;
TargetUser = model.TargetUser.IsSpecified ? RestUser.Create(Discord, model.TargetUser.Value) : null;
TargetUserType = model.TargetUserType.IsSpecified ? model.TargetUserType.Value : TargetUserType.Undefined;
}

/// <inheritdoc />
Expand Down
20 changes: 6 additions & 14 deletions src/Discord.Net.Rest/Entities/Invites/RestInviteMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ namespace Discord.Rest
/// <summary> Represents additional information regarding the REST-based invite object. </summary>
public class RestInviteMetadata : RestInvite, IInviteMetadata
{
private long? _createdAtTicks;
private long _createdAtTicks;

/// <inheritdoc />
[Obsolete("This property doesn't exist anymore and shouldn't be used.")]
public bool IsRevoked { get; private set; }
/// <inheritdoc />
public bool IsTemporary { get; private set; }
Expand All @@ -18,10 +19,6 @@ public class RestInviteMetadata : RestInvite, IInviteMetadata
public int? MaxUses { get; private set; }
/// <inheritdoc />
public int? Uses { get; private set; }
/// <summary>
/// Gets the user that created this invite.
/// </summary>
public RestUser Inviter { get; private set; }

/// <inheritdoc />
public DateTimeOffset? CreatedAt => DateTimeUtils.FromTicks(_createdAtTicks);
Expand All @@ -39,16 +36,11 @@ internal static RestInviteMetadata Create(BaseDiscordClient discord, IGuild guil
internal void Update(Model model)
{
base.Update(model);
Inviter = model.Inviter != null ? RestUser.Create(Discord, model.Inviter) : null;
IsRevoked = model.Revoked;
IsTemporary = model.Temporary;
MaxAge = model.MaxAge.IsSpecified ? model.MaxAge.Value : (int?)null;
MaxUses = model.MaxUses.IsSpecified ? model.MaxUses.Value : (int?)null;
Uses = model.Uses.IsSpecified ? model.Uses.Value : (int?)null;
_createdAtTicks = model.CreatedAt.IsSpecified ? model.CreatedAt.Value.UtcTicks : (long?)null;
MaxAge = model.MaxAge;
MaxUses = model.MaxUses;
Uses = model.Uses;
_createdAtTicks = model.CreatedAt.UtcTicks;
}

/// <inheritdoc />
IUser IInviteMetadata.Inviter => Inviter;
}
}
5 changes: 4 additions & 1 deletion src/Discord.Net.WebSocket/Entities/Invites/SocketInvite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ ChannelType IInvite.ChannelType
/// <inheritdoc />
int? IInvite.MemberCount => throw new NotImplementedException();
/// <inheritdoc />
[Obsolete("This property doesn't exist anymore and shouldn't be used.")]
bool IInviteMetadata.IsRevoked => throw new NotImplementedException();
/// <inheritdoc />
public bool IsTemporary { get; private set; }
Expand Down Expand Up @@ -138,6 +139,8 @@ public Task DeleteAsync(RequestOptions options = null)
/// <inheritdoc />
IChannel IInvite.Channel => Channel;
/// <inheritdoc />
IUser IInviteMetadata.Inviter => Inviter;
IUser IInvite.Inviter => Inviter;
/// <inheritdoc />
IUser IInvite.TargetUser => TargetUser;
}
}

0 comments on commit dd2e524

Please sign in to comment.