Browse Source

Update status of CurrentUser when status or currentgame is changed

tags/docs-0.9
RogueException 9 years ago
parent
commit
a4447d759d
4 changed files with 24 additions and 5 deletions
  1. +11
    -0
      src/Discord.Net/DiscordClient.cs
  2. +6
    -3
      src/Discord.Net/Extensions.cs
  3. +5
    -0
      src/Discord.Net/Models/Server.cs
  4. +2
    -2
      src/Discord.Net/Models/User.cs

+ 11
- 0
src/Discord.Net/DiscordClient.cs View File

@@ -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;
}


+ 6
- 3
src/Discord.Net/Extensions.cs View File

@@ -29,15 +29,18 @@ namespace Discord

public static bool TryGetOrAdd<TKey, TValue>(this ConcurrentDictionary<TKey, TValue> d,
TKey key, Func<TKey, TValue> 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;


+ 5
- 0
src/Discord.Net/Models/Server.cs View File

@@ -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;
}


+ 2
- 2
src/Discord.Net/Models/User.cs View File

@@ -59,9 +59,9 @@ namespace Discord
/// <summary> Gets the unique identifier for this user's current avatar. </summary>
public string AvatarId { get; private set; }
/// <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>
public UserStatus Status { get; private set; }
public UserStatus Status { get; internal set; }
/// <summary> Gets the datetime that this user joined this server. </summary>
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>


Loading…
Cancel
Save