Skip to content

Commit

Permalink
fix: thread owner always null (#2182)
Browse files Browse the repository at this point in the history
  • Loading branch information
quinchs committed Mar 9, 2022
1 parent f8ec3c7 commit 25aaa49
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/Discord.Net.WebSocket/Entities/Channels/SocketThreadChannel.cs
Expand Up @@ -24,7 +24,29 @@ public class SocketThreadChannel : SocketTextChannel, IThreadChannel
/// <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.
Expand Down Expand Up @@ -83,6 +105,9 @@ public bool IsPrivateThread
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)
Expand Down Expand Up @@ -120,7 +145,7 @@ internal override void Update(ClientState state, Model model)

if (model.OwnerId.IsSpecified)
{
Owner = GetUser(model.OwnerId.Value);
_ownerId = model.OwnerId.Value;
}

HasJoined = model.ThreadMember.IsSpecified;
Expand Down
11 changes: 11 additions & 0 deletions src/Discord.Net.WebSocket/Entities/Users/SocketThreadUser.cs
Expand Up @@ -147,6 +147,17 @@ internal static SocketThreadUser Create(SocketGuild guild, SocketThreadChannel t
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)
{
ThreadJoinedAt = model.JoinTimestamp;
Expand Down

0 comments on commit 25aaa49

Please sign in to comment.