From 96a832788c16f4fe254f0e5035db6459705b5b2c Mon Sep 17 00:00:00 2001
From: Mihail Gribkov <61027276+Misha-133@users.noreply.github.com>
Date: Sat, 23 Nov 2024 20:31:10 +0300
Subject: [PATCH] [Fix] NRE on thread member creation without a guild user in
the payload (#3030)
lets hope for the best
---
.../Entities/Channels/SocketThreadChannel.cs | 6 +++---
.../Entities/Users/SocketThreadUser.cs | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketThreadChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketThreadChannel.cs
index 3df89d8417..5f476d89a1 100644
--- a/src/Discord.Net.WebSocket/Entities/Channels/SocketThreadChannel.cs
+++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketThreadChannel.cs
@@ -178,14 +178,14 @@ internal SocketThreadUser AddOrUpdateThreadMember(ThreadMember model, SocketGuil
member.Update(model);
else
{
- member = SocketThreadUser.Create(Guild, this, model, guildMember);
- member.GlobalUser.AddRef();
+ member = SocketThreadUser.Create(Guild, this, model, guildMember ?? Guild.GetUser(model.UserId.GetValueOrDefault(0)));
+ member.GlobalUser?.AddRef();
_members[member.Id] = member;
}
return member;
}
- ///
+ ///
public new SocketThreadUser GetUser(ulong id)
{
var user = Users.FirstOrDefault(x => x.Id == id);
diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketThreadUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketThreadUser.cs
index b5859e772b..d87da400f7 100644
--- a/src/Discord.Net.WebSocket/Entities/Users/SocketThreadUser.cs
+++ b/src/Discord.Net.WebSocket/Entities/Users/SocketThreadUser.cs
@@ -251,9 +251,9 @@ internal void Update(Model model)
public override string GetDisplayAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
=> GuildUser.GetGuildAvatarUrl() ?? base.GetDisplayAvatarUrl(format, size);
- internal override SocketGlobalUser GlobalUser { get => GuildUser.GlobalUser; set => GuildUser.GlobalUser = value; }
+ internal override SocketGlobalUser GlobalUser { get => GuildUser?.GlobalUser; set => GuildUser.GlobalUser = value; }
- internal override SocketPresence Presence { get => GuildUser.Presence; set => GuildUser.Presence = value; }
+ internal override SocketPresence Presence { get => GuildUser?.Presence; set => GuildUser.Presence = value; }
///
/// Gets the guild user of this thread user.