Skip to content

Commit

Permalink
Adds BoostSubscriptionMetadata.IsValid and SocketGuild.ValidBoostSubs…
Browse files Browse the repository at this point in the history
…criptions
  • Loading branch information
gehongyan committed Nov 11, 2022
1 parent 2fd8cc6 commit c305ace
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Kook.Net.Core/Entities/Users/BoostSubscriptionMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,24 @@ namespace Kook;
/// </summary>
public class BoostSubscriptionMetadata
{
/// <summary>
/// Gets the date and time when this subscription began.
/// </summary>
public DateTimeOffset Since { get; private set; }

/// <summary>
/// Gets the date and time when this subscription will end or ended.
/// </summary>
public DateTimeOffset Until { get; private set; }

/// <summary>
/// Gets whether this subscription has not expired.
/// </summary>
public bool IsValid => DateTimeOffset.Now < Until;

/// <summary>
/// Gets how many boost packs the user used for this subscription.
/// </summary>
public int Count { get; private set; }

internal BoostSubscriptionMetadata(DateTimeOffset since, DateTimeOffset until, int count)
Expand Down
32 changes: 32 additions & 0 deletions src/Kook.Net.WebSocket/Entities/Guilds/SocketGuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,43 @@ public IReadOnlyCollection<SocketGuildChannel> Channels
/// </para>
/// </note>
/// </remarks>
/// <seealso cref="ValidBoostSubscriptions"/>
/// <seealso cref="DownloadBoostSubscriptionsAsync"/>
/// <seealso cref="KookSocketClient.DownloadBoostSubscriptionsAsync"/>
/// <seealso cref="KookSocketClient.AlwaysDownloadBoostSubscriptions"/>
public ImmutableDictionary<IUser, IReadOnlyCollection<BoostSubscriptionMetadata>> BoostSubscriptions => _boostSubscriptions?.ToImmutableDictionary();
/// <summary>
/// Gets a dictionary of all boost subscriptions which have not expired for this guild.
/// </summary>
/// <returns>
/// A read-only dictionary containing all boost subscription metadata which have not expired for this guild grouped by users;
/// or <see langword="null"/> if the boost subscription data has never been cached.
/// </returns>
/// <remarks>
/// <note type="warning">
/// <para>
/// Only when <see cref="KookSocketConfig.AlwaysDownloadBoostSubscriptions"/> is set to <see langword="true"/>
/// will this property be populated upon startup. Due to the lack of event support for boost subscriptions,
/// this property will never be updated. The changes of <see cref="SocketGuild.BoostSubscriptionCount"/> will trigger the update
/// of this property, but KOOK gateway will not publish this event resulting from the changes of total boost subscription
/// count. To fetch the latest boost subscription data, use <see cref="DownloadBoostSubscriptionsAsync"/> or
/// <see cref="KookSocketClient.DownloadBoostSubscriptionsAsync"/> upon a <see cref="KookSocketClient"/> to
/// manually download the latest boost subscription data, or <see cref="GetBoostSubscriptionsAsync"/>.
/// </para>
/// </note>
/// </remarks>
/// <seealso cref="BoostSubscriptions"/>
/// <seealso cref="DownloadBoostSubscriptionsAsync"/>
/// <seealso cref="KookSocketClient.DownloadBoostSubscriptionsAsync"/>
/// <seealso cref="KookSocketClient.AlwaysDownloadBoostSubscriptions"/>
public ImmutableDictionary<IUser, IReadOnlyCollection<BoostSubscriptionMetadata>> ValidBoostSubscriptions =>
_boostSubscriptions?.Select(x =>
new KeyValuePair<IUser, IReadOnlyCollection<BoostSubscriptionMetadata>>(x.Key, x.Value
.Where(y => y.IsValid)
.ToImmutableArray() as IReadOnlyCollection<BoostSubscriptionMetadata>))
.Where(x => x.Value.Any())
.ToImmutableDictionary();
/// <summary>
/// Gets a collection of users in this guild.
/// </summary>
/// <remarks>
Expand Down

0 comments on commit c305ace

Please sign in to comment.