Update status of CurrentUser when status or currentgame is changed

This commit is contained in:
RogueException
2015-12-24 00:11:52 -04:00
parent 6f1afcccad
commit a4447d759d
4 changed files with 24 additions and 5 deletions

View File

@@ -304,6 +304,17 @@ namespace Discord
} }
private Task SendStatus() 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); GatewaySocket.SendUpdateStatus(Status == UserStatus.Idle ? EpochTime.GetMilliseconds() - (10 * 60 * 1000) : (long?)null, CurrentGame);
return TaskHelper.CompletedTask; return TaskHelper.CompletedTask;
} }

View File

@@ -29,15 +29,18 @@ namespace Discord
public static bool TryGetOrAdd<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> d, public static bool TryGetOrAdd<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> d,
TKey key, Func<TKey, TValue> factory, out TValue result) TKey key, Func<TKey, TValue> factory, out TValue result)
where TValue : class
{ {
TValue newValue = null; bool created = false;
TValue newValue = default(TValue);
while (true) while (true)
{ {
if (d.TryGetValue(key, out result)) if (d.TryGetValue(key, out result))
return false; return false;
if (newValue == null) if (!created)
{
newValue = factory(key); newValue = factory(key);
created = true;
}
if (d.TryAdd(key, newValue)) if (d.TryAdd(key, newValue))
{ {
result = newValue; result = newValue;

View File

@@ -391,6 +391,11 @@ namespace Discord
{ {
foreach (var channel in AllChannels) foreach (var channel in AllChannels)
channel.AddUser(user.User); channel.AddUser(user.User);
if (id == Client.CurrentUser.Id)
{
user.User.CurrentGame = Client.CurrentGame;
user.User.Status = Client.Status;
}
} }
return user.User; return user.User;
} }

View File

@@ -59,9 +59,9 @@ namespace Discord
/// <summary> Gets the unique identifier for this user's current avatar. </summary> /// <summary> Gets the unique identifier for this user's current avatar. </summary>
public string AvatarId { get; private set; } public string AvatarId { get; private set; }
/// <summary> Gets the name of the game this user is currently playing. </summary> /// <summary> Gets the name of the game this user is currently playing. </summary>
public string CurrentGame { get; private set; } public string CurrentGame { get; internal set; }
/// <summary> Gets the current status for this user. </summary> /// <summary> Gets the current status for this user. </summary>
public UserStatus Status { get; private set; } public UserStatus Status { get; internal set; }
/// <summary> Gets the datetime that this user joined this server. </summary> /// <summary> Gets the datetime that this user joined this server. </summary>
public DateTime JoinedAt { get; private set; } public DateTime JoinedAt { get; private set; }
/// <summary> Returns the time this user last sent/edited a message, started typing or sent voice data in this server. </summary> /// <summary> Returns the time this user last sent/edited a message, started typing or sent voice data in this server. </summary>