浏览代码

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

pull/6/head
Brandon Smith 9 年前
父节点
当前提交
2a61e87e58
共有 2 个文件被更改,包括 11 次插入8 次删除
  1. +6
    -0
      src/Discord.Net/DiscordClient.cs
  2. +5
    -8
      src/Discord.Net/Models/User.cs

+ 6
- 0
src/Discord.Net/DiscordClient.cs 查看文件

@@ -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 查看文件

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


正在加载...
取消
保存