Browse Source

Default LastActivity to null until activity is seen, trigger with voice activity.

tags/docs-0.9
Brandon Smith 9 years ago
parent
commit
2a61e87e58
2 changed files with 11 additions and 8 deletions
  1. +6
    -0
      src/Discord.Net/DiscordClient.cs
  2. +5
    -8
      src/Discord.Net/Models/User.cs

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

@@ -118,6 +118,12 @@ namespace Discord
{
if (_voiceSocket.CurrentVoiceServerId != null)
{
if (_config.TrackActivity)
{
var user = _users[e.UserId];
if (user != null)
user.UpdateActivity();
}
var member = _members[e.UserId, _voiceSocket.CurrentVoiceServerId];
bool value = e.IsSpeaking;
if (member.IsSpeaking != value)


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

@@ -44,17 +44,14 @@ namespace Discord
public IEnumerable<Server> Servers => _client.Servers.Where(x => x.HasMember(Id));
/// <summary> Returns a collection of all messages this user has sent that are still in cache. </summary>
public IEnumerable<Message> Messages => _client.Messages.Where(x => x.UserId == Id);

//TODO: Add voice triggering LastActivity
/// <summary> Returns the time this user last sent a message. </summary>
/// <remarks> Is not currently affected by voice activity. </remarks>
public DateTime LastActivity { get; private set; }
public DateTime? LastActivity { get; private set; }

internal User(DiscordClient client, string id)
{
_client = client;
Id = id;
LastActivity = DateTime.UtcNow;
}

internal void Update(UserReference model)
@@ -70,10 +67,10 @@ namespace Discord
IsVerified = model.IsVerified;
}

internal void UpdateActivity(DateTime activity)
internal void UpdateActivity(DateTime? activity)
{
if (activity > LastActivity)
LastActivity = activity;
if (LastActivity == null || activity > LastActivity.Value)
LastActivity = activity ?? DateTime.UtcNow;
}

public override string ToString() => Name;


Loading…
Cancel
Save