fix: thread owner always null (#2182)

This commit is contained in:
Quin Lynch
2022-03-09 17:29:24 -04:00
committed by GitHub
parent f8ec3c79c2
commit 25aaa4948a
2 changed files with 38 additions and 2 deletions

View File

@@ -24,7 +24,29 @@ namespace Discord.WebSocket
/// <summary>
/// Gets the owner of the current thread.
/// </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>
/// Gets the current users within this thread.
@@ -83,6 +105,9 @@ namespace Discord.WebSocket
private bool _usersDownloaded;
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,
DateTimeOffset? createdAt)
@@ -120,7 +145,7 @@ namespace Discord.WebSocket
if (model.OwnerId.IsSpecified)
{
Owner = GetUser(model.OwnerId.Value);
_ownerId = model.OwnerId.Value;
}
HasJoined = model.ThreadMember.IsSpecified;