fix: thread owner always null (#2182)
This commit is contained in:
@@ -24,7 +24,29 @@ namespace Discord.WebSocket
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the owner of the current thread.
|
/// Gets the owner of the current thread.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public SocketThreadUser Owner { get; private set; }
|
public SocketThreadUser Owner
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
lock (_ownerLock)
|
||||||
|
{
|
||||||
|
var user = GetUser(_ownerId);
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
var guildMember = Guild.GetUser(_ownerId);
|
||||||
|
if (guildMember == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
user = SocketThreadUser.Create(Guild, this, guildMember);
|
||||||
|
_members[user.Id] = user;
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the current users within this thread.
|
/// Gets the current users within this thread.
|
||||||
@@ -83,6 +105,9 @@ namespace Discord.WebSocket
|
|||||||
private bool _usersDownloaded;
|
private bool _usersDownloaded;
|
||||||
|
|
||||||
private readonly object _downloadLock = new object();
|
private readonly object _downloadLock = new object();
|
||||||
|
private readonly object _ownerLock = new object();
|
||||||
|
|
||||||
|
private ulong _ownerId;
|
||||||
|
|
||||||
internal SocketThreadChannel(DiscordSocketClient discord, SocketGuild guild, ulong id, SocketGuildChannel parent,
|
internal SocketThreadChannel(DiscordSocketClient discord, SocketGuild guild, ulong id, SocketGuildChannel parent,
|
||||||
DateTimeOffset? createdAt)
|
DateTimeOffset? createdAt)
|
||||||
@@ -120,7 +145,7 @@ namespace Discord.WebSocket
|
|||||||
|
|
||||||
if (model.OwnerId.IsSpecified)
|
if (model.OwnerId.IsSpecified)
|
||||||
{
|
{
|
||||||
Owner = GetUser(model.OwnerId.Value);
|
_ownerId = model.OwnerId.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
HasJoined = model.ThreadMember.IsSpecified;
|
HasJoined = model.ThreadMember.IsSpecified;
|
||||||
|
|||||||
@@ -147,6 +147,17 @@ namespace Discord.WebSocket
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static SocketThreadUser Create(SocketGuild guild, SocketThreadChannel thread, SocketGuildUser owner)
|
||||||
|
{
|
||||||
|
// this is used for creating the owner of the thread.
|
||||||
|
var entity = new SocketThreadUser(guild, thread, owner, owner.Id);
|
||||||
|
entity.Update(new Model
|
||||||
|
{
|
||||||
|
JoinTimestamp = thread.CreatedAt,
|
||||||
|
});
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
internal void Update(Model model)
|
internal void Update(Model model)
|
||||||
{
|
{
|
||||||
ThreadJoinedAt = model.JoinTimestamp;
|
ThreadJoinedAt = model.JoinTimestamp;
|
||||||
|
|||||||
Reference in New Issue
Block a user