Browse Source

Add IsInvitable and CreatedAt to threads (#2153)

* Add IsInvitable and CreatedAt to threads

* Update src/Discord.Net.Core/Entities/Channels/IThreadChannel.cs

Co-Authored-By: Jared L <48422312+lhjt@users.noreply.github.com>

Co-authored-by: Jared L <48422312+lhjt@users.noreply.github.com>
tags/3.4.0
Quin Lynch GitHub 3 years ago
parent
commit
6bf5818e72
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 9 deletions
  1. +17
    -0
      src/Discord.Net.Core/Entities/Channels/IThreadChannel.cs
  2. +6
    -0
      src/Discord.Net.Rest/API/Common/ThreadMetadata.cs
  3. +1
    -1
      src/Discord.Net.Rest/Entities/Channels/RestChannel.cs
  4. +13
    -3
      src/Discord.Net.Rest/Entities/Channels/RestThreadChannel.cs
  5. +1
    -1
      src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs
  6. +13
    -4
      src/Discord.Net.WebSocket/Entities/Channels/SocketThreadChannel.cs

+ 17
- 0
src/Discord.Net.Core/Entities/Channels/IThreadChannel.cs View File

@@ -48,6 +48,23 @@ namespace Discord
/// </summary> /// </summary>
int MessageCount { get; } int MessageCount { get; }


/// <summary>
/// Gets whether non-moderators can add other non-moderators to a thread.
/// </summary>
/// <remarks>
/// This property is only available on private threads.
/// </remarks>
bool? IsInvitable { get; }

/// <summary>
/// Gets when the thread was created.
/// </summary>
/// <remarks>
/// This property is only populated for threads created after 2022-01-09, hence the default date of this
/// property will be that date.
/// </remarks>
new DateTimeOffset CreatedAt { get; }

/// <summary> /// <summary>
/// Joins the current thread. /// Joins the current thread.
/// </summary> /// </summary>


+ 6
- 0
src/Discord.Net.Rest/API/Common/ThreadMetadata.cs View File

@@ -16,5 +16,11 @@ namespace Discord.API


[JsonProperty("locked")] [JsonProperty("locked")]
public Optional<bool> Locked { get; set; } public Optional<bool> Locked { get; set; }

[JsonProperty("invitable")]
public Optional<bool> Invitable { get; set; }

[JsonProperty("create_timestamp")]
public Optional<DateTimeOffset> CreatedAt { get; set; }
} }
} }

+ 1
- 1
src/Discord.Net.Rest/Entities/Channels/RestChannel.cs View File

@@ -13,7 +13,7 @@ namespace Discord.Rest
{ {
#region RestChannel #region RestChannel
/// <inheritdoc /> /// <inheritdoc />
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
public virtual DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);


internal RestChannel(BaseDiscordClient discord, ulong id) internal RestChannel(BaseDiscordClient discord, ulong id)
: base(discord, id) : base(discord, id)


+ 13
- 3
src/Discord.Net.Rest/Entities/Channels/RestThreadChannel.cs View File

@@ -34,17 +34,26 @@ namespace Discord.Rest
/// <inheritdoc/> /// <inheritdoc/>
public int MessageCount { get; private set; } public int MessageCount { get; private set; }


/// <inheritdoc/>
public bool? IsInvitable { get; private set; }

/// <inheritdoc cref="IThreadChannel.CreatedAt"/>
public override DateTimeOffset CreatedAt { get; }

/// <summary> /// <summary>
/// Gets the parent text channel id. /// Gets the parent text channel id.
/// </summary> /// </summary>
public ulong ParentChannelId { get; private set; } public ulong ParentChannelId { get; private set; }


internal RestThreadChannel(BaseDiscordClient discord, IGuild guild, ulong id)
: base(discord, guild, id) { }
internal RestThreadChannel(BaseDiscordClient discord, IGuild guild, ulong id, DateTimeOffset? createdAt)
: base(discord, guild, id)
{
CreatedAt = createdAt ?? new DateTimeOffset(2022, 1, 9, 0, 0, 0, TimeSpan.Zero);
}


internal new static RestThreadChannel Create(BaseDiscordClient discord, IGuild guild, Model model) internal new static RestThreadChannel Create(BaseDiscordClient discord, IGuild guild, Model model)
{ {
var entity = new RestThreadChannel(discord, guild, model.Id);
var entity = new RestThreadChannel(discord, guild, model.Id, model.ThreadMetadata.GetValueOrDefault()?.CreatedAt.GetValueOrDefault());
entity.Update(model); entity.Update(model);
return entity; return entity;
} }
@@ -57,6 +66,7 @@ namespace Discord.Rest


if (model.ThreadMetadata.IsSpecified) if (model.ThreadMetadata.IsSpecified)
{ {
IsInvitable = model.ThreadMetadata.Value.Invitable.ToNullable();
IsArchived = model.ThreadMetadata.Value.Archived; IsArchived = model.ThreadMetadata.Value.Archived;
AutoArchiveDuration = model.ThreadMetadata.Value.AutoArchiveDuration; AutoArchiveDuration = model.ThreadMetadata.Value.AutoArchiveDuration;
ArchiveTimestamp = model.ThreadMetadata.Value.ArchiveTimestamp; ArchiveTimestamp = model.ThreadMetadata.Value.ArchiveTimestamp;


+ 1
- 1
src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs View File

@@ -17,7 +17,7 @@ namespace Discord.WebSocket
/// <summary> /// <summary>
/// Gets when the channel is created. /// Gets when the channel is created.
/// </summary> /// </summary>
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
public virtual DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
/// <summary> /// <summary>
/// Gets a collection of users from the WebSocket cache. /// Gets a collection of users from the WebSocket cache.
/// </summary> /// </summary>


+ 13
- 4
src/Discord.Net.WebSocket/Entities/Channels/SocketThreadChannel.cs View File

@@ -44,7 +44,7 @@ namespace Discord.WebSocket
/// <summary> /// <summary>
/// Gets the parent channel this thread resides in. /// Gets the parent channel this thread resides in.
/// </summary> /// </summary>
public SocketTextChannel ParentChannel { get; private set; }
public SocketGuildChannel ParentChannel { get; private set; }


/// <inheritdoc/> /// <inheritdoc/>
public int MessageCount { get; private set; } public int MessageCount { get; private set; }
@@ -64,6 +64,12 @@ namespace Discord.WebSocket
/// <inheritdoc/> /// <inheritdoc/>
public bool IsLocked { get; private set; } public bool IsLocked { get; private set; }


/// <inheritdoc/>
public bool? IsInvitable { get; private set; }

/// <inheritdoc cref="IThreadChannel.CreatedAt"/>
public override DateTimeOffset CreatedAt { get; }

/// <summary> /// <summary>
/// Gets a collection of cached users within this thread. /// Gets a collection of cached users within this thread.
/// </summary> /// </summary>
@@ -78,17 +84,19 @@ namespace Discord.WebSocket


private readonly object _downloadLock = new object(); private readonly object _downloadLock = new object();


internal SocketThreadChannel(DiscordSocketClient discord, SocketGuild guild, ulong id, SocketTextChannel parent)
internal SocketThreadChannel(DiscordSocketClient discord, SocketGuild guild, ulong id, SocketGuildChannel parent,
DateTimeOffset? createdAt)
: base(discord, id, guild) : base(discord, id, guild)
{ {
ParentChannel = parent; ParentChannel = parent;
_members = new ConcurrentDictionary<ulong, SocketThreadUser>(); _members = new ConcurrentDictionary<ulong, SocketThreadUser>();
CreatedAt = createdAt ?? new DateTimeOffset(2022, 1, 9, 0, 0, 0, TimeSpan.Zero);
} }


internal new static SocketThreadChannel Create(SocketGuild guild, ClientState state, Model model) internal new static SocketThreadChannel Create(SocketGuild guild, ClientState state, Model model)
{ {
var parent = (SocketTextChannel)guild.GetChannel(model.CategoryId.Value);
var entity = new SocketThreadChannel(guild.Discord, guild, model.Id, parent);
var parent = guild.GetChannel(model.CategoryId.Value);
var entity = new SocketThreadChannel(guild.Discord, guild, model.Id, parent, model.ThreadMetadata.GetValueOrDefault()?.CreatedAt.ToNullable());
entity.Update(state, model); entity.Update(state, model);
return entity; return entity;
} }
@@ -103,6 +111,7 @@ namespace Discord.WebSocket


if (model.ThreadMetadata.IsSpecified) if (model.ThreadMetadata.IsSpecified)
{ {
IsInvitable = model.ThreadMetadata.Value.Invitable.ToNullable();
IsArchived = model.ThreadMetadata.Value.Archived; IsArchived = model.ThreadMetadata.Value.Archived;
ArchiveTimestamp = model.ThreadMetadata.Value.ArchiveTimestamp; ArchiveTimestamp = model.ThreadMetadata.Value.ArchiveTimestamp;
AutoArchiveDuration = model.ThreadMetadata.Value.AutoArchiveDuration; AutoArchiveDuration = model.ThreadMetadata.Value.AutoArchiveDuration;


Loading…
Cancel
Save