[Feature] Rework Thread property of a message (#2579)
* move `Thread` property to `IUserMessage` & add one to `SocketUserMessage` * get channel from cache instead of creating new object * move the property back to IMessage
This commit is contained in:
@@ -89,6 +89,14 @@ namespace Discord
|
||||
/// </summary>
|
||||
IUser Author { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the thread that was started from this message.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// An <see cref="IThreadChannel"/> object if this message has thread attached; otherwise <see langword="null"/>.
|
||||
/// </returns>
|
||||
IThreadChannel Thread { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets all attachments included in this message.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
using Discord.API;
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Model = Discord.API.Message;
|
||||
|
||||
namespace Discord.Rest
|
||||
@@ -45,6 +49,12 @@ namespace Discord.Rest
|
||||
/// <inheritdoc />
|
||||
public virtual bool MentionedEveryone => false;
|
||||
|
||||
/// <inheritdoc cref="IMessage.Thread"/>
|
||||
public RestThreadChannel Thread { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
IThreadChannel IMessage.Thread => Thread;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of the <see cref="Attachment"/>'s on the message.
|
||||
/// </summary>
|
||||
@@ -80,15 +90,6 @@ namespace Discord.Rest
|
||||
/// <inheritdoc/>
|
||||
public MessageType Type { get; private set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the thread that was started from this message.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A <see cref="RestThreadChannel"/> object if this message has thread attached; otherwise <see langword="null"/>.
|
||||
/// </returns>
|
||||
public RestThreadChannel Thread { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public MessageRoleSubscriptionData RoleSubscriptionData { get; private set; }
|
||||
|
||||
@@ -266,9 +267,7 @@ namespace Discord.Rest
|
||||
}
|
||||
|
||||
if (model.Thread.IsSpecified)
|
||||
{
|
||||
Thread = RestThreadChannel.Create(Discord, new RestGuild(Discord, model.Thread.Value.GuildId.Value), model.Thread.Value);
|
||||
}
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public async Task UpdateAsync(RequestOptions options = null)
|
||||
@@ -310,7 +309,7 @@ namespace Discord.Rest
|
||||
|
||||
/// <inheritdoc />
|
||||
IReadOnlyCollection<IStickerItem> IMessage.Stickers => Stickers;
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -81,6 +81,12 @@ namespace Discord.WebSocket
|
||||
/// <inheritdoc />
|
||||
public MessageRoleSubscriptionData RoleSubscriptionData { get; private set; }
|
||||
|
||||
/// <inheritdoc cref="IMessage.Thread"/>
|
||||
public SocketThreadChannel Thread { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
IThreadChannel IMessage.Thread => Thread;
|
||||
|
||||
/// <summary>
|
||||
/// Returns all attachments included in this message.
|
||||
/// </summary>
|
||||
@@ -283,6 +289,12 @@ namespace Discord.WebSocket
|
||||
model.RoleSubscriptionData.Value.MonthsSubscribed,
|
||||
model.RoleSubscriptionData.Value.IsRenewal);
|
||||
}
|
||||
|
||||
if (model.Thread.IsSpecified)
|
||||
{
|
||||
SocketGuild guild = (Channel as SocketGuildChannel)?.Guild;
|
||||
Thread = guild?.AddOrUpdateChannel(state, model.Thread.Value) as SocketThreadChannel;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
Reference in New Issue
Block a user