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 (_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)

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;