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

This commit is contained in:
Brandon Smith
2015-09-21 14:54:25 -03:00
parent 1c2bb281d2
commit 2a61e87e58
2 changed files with 11 additions and 8 deletions

View File

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

View File

@@ -45,16 +45,13 @@ namespace Discord
/// <summary> Returns a collection of all messages this user has sent that are still in cache. </summary> /// <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); 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> /// <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) internal User(DiscordClient client, string id)
{ {
_client = client; _client = client;
Id = id; Id = id;
LastActivity = DateTime.UtcNow;
} }
internal void Update(UserReference model) internal void Update(UserReference model)
@@ -70,10 +67,10 @@ namespace Discord
IsVerified = model.IsVerified; IsVerified = model.IsVerified;
} }
internal void UpdateActivity(DateTime activity) internal void UpdateActivity(DateTime? activity)
{ {
if (activity > LastActivity) if (LastActivity == null || activity > LastActivity.Value)
LastActivity = activity; LastActivity = activity ?? DateTime.UtcNow;
} }
public override string ToString() => Name; public override string ToString() => Name;