diff --git a/src/Discord.Net/DiscordClient.cs b/src/Discord.Net/DiscordClient.cs index c541fa5a2..f27e68299 100644 --- a/src/Discord.Net/DiscordClient.cs +++ b/src/Discord.Net/DiscordClient.cs @@ -304,6 +304,17 @@ namespace Discord } private Task SendStatus() { + PrivateUser.Status = Status; + PrivateUser.CurrentGame = CurrentGame; + foreach (var server in Servers) + { + var current = server.CurrentUser; + if (current != null) + { + current.Status = Status; + current.CurrentGame = CurrentGame; + } + } GatewaySocket.SendUpdateStatus(Status == UserStatus.Idle ? EpochTime.GetMilliseconds() - (10 * 60 * 1000) : (long?)null, CurrentGame); return TaskHelper.CompletedTask; } diff --git a/src/Discord.Net/Extensions.cs b/src/Discord.Net/Extensions.cs index 2d843cef9..4f4850312 100644 --- a/src/Discord.Net/Extensions.cs +++ b/src/Discord.Net/Extensions.cs @@ -29,15 +29,18 @@ namespace Discord public static bool TryGetOrAdd(this ConcurrentDictionary d, TKey key, Func factory, out TValue result) - where TValue : class { - TValue newValue = null; + bool created = false; + TValue newValue = default(TValue); while (true) { if (d.TryGetValue(key, out result)) return false; - if (newValue == null) + if (!created) + { newValue = factory(key); + created = true; + } if (d.TryAdd(key, newValue)) { result = newValue; diff --git a/src/Discord.Net/Models/Server.cs b/src/Discord.Net/Models/Server.cs index 98233ce84..04fc8a15a 100644 --- a/src/Discord.Net/Models/Server.cs +++ b/src/Discord.Net/Models/Server.cs @@ -391,6 +391,11 @@ namespace Discord { foreach (var channel in AllChannels) channel.AddUser(user.User); + if (id == Client.CurrentUser.Id) + { + user.User.CurrentGame = Client.CurrentGame; + user.User.Status = Client.Status; + } } return user.User; } diff --git a/src/Discord.Net/Models/User.cs b/src/Discord.Net/Models/User.cs index 2d70404e7..d483601eb 100644 --- a/src/Discord.Net/Models/User.cs +++ b/src/Discord.Net/Models/User.cs @@ -59,9 +59,9 @@ namespace Discord /// Gets the unique identifier for this user's current avatar. public string AvatarId { get; private set; } /// Gets the name of the game this user is currently playing. - public string CurrentGame { get; private set; } + public string CurrentGame { get; internal set; } /// Gets the current status for this user. - public UserStatus Status { get; private set; } + public UserStatus Status { get; internal set; } /// Gets the datetime that this user joined this server. public DateTime JoinedAt { get; private set; } /// Returns the time this user last sent/edited a message, started typing or sent voice data in this server.