@@ -719,6 +719,7 @@ namespace Discord | |||||
{ | { | ||||
CheckReady(); | CheckReady(); | ||||
var response = await _api.ChangeUsername(newName, currentEmail, currentPassword).ConfigureAwait(false); | var response = await _api.ChangeUsername(newName, currentEmail, currentPassword).ConfigureAwait(false); | ||||
_currentUser.Update(response); | |||||
foreach (var membership in _currentUser.Memberships) | foreach (var membership in _currentUser.Memberships) | ||||
membership.Update(response); | membership.Update(response); | ||||
} | } | ||||
@@ -742,6 +743,7 @@ namespace Discord | |||||
{ | { | ||||
CheckReady(); | CheckReady(); | ||||
var response = await _api.ChangeAvatar(imageType, bytes, currentEmail, currentPassword).ConfigureAwait(false); | var response = await _api.ChangeAvatar(imageType, bytes, currentEmail, currentPassword).ConfigureAwait(false); | ||||
_currentUser.Update(response); | |||||
foreach (var membership in _currentUser.Memberships) | foreach (var membership in _currentUser.Memberships) | ||||
membership.Update(response); | membership.Update(response); | ||||
} | } | ||||
@@ -353,7 +353,9 @@ namespace Discord | |||||
case "GUILD_MEMBER_ADD": | case "GUILD_MEMBER_ADD": | ||||
{ | { | ||||
var data = e.Payload.ToObject<Events.GuildMemberAdd>(_serializer); | var data = e.Payload.ToObject<Events.GuildMemberAdd>(_serializer); | ||||
var user = _users.GetOrAdd(data.User.Id); | |||||
var member = _members.GetOrAdd(data.User.Id, data.GuildId); | var member = _members.GetOrAdd(data.User.Id, data.GuildId); | ||||
user.Update(data.User); | |||||
member.Update(data); | member.Update(data); | ||||
if (_config.TrackActivity) | if (_config.TrackActivity) | ||||
member.UpdateActivity(); | member.UpdateActivity(); | ||||
@@ -12,12 +12,13 @@ namespace Discord | |||||
/// <summary> Returns the name of this user on this server. </summary> | /// <summary> Returns the name of this user on this server. </summary> | ||||
public string Name { get; internal set; } | public string Name { get; internal set; } | ||||
/// <summary> Returns a by-name unique identifier separating this user from others with the same name. </summary> | |||||
public string Discriminator { get; internal set; } | |||||
/// <summary> Returns the unique identifier for this user's current avatar. </summary> | /// <summary> Returns the unique identifier for this user's current avatar. </summary> | ||||
public string AvatarId { get; internal set; } | public string AvatarId { get; internal set; } | ||||
/// <summary> Returns the URL to this user's current avatar. </summary> | /// <summary> Returns the URL to this user's current avatar. </summary> | ||||
public string AvatarUrl => Endpoints.UserAvatar(UserId, AvatarId); | public string AvatarUrl => Endpoints.UserAvatar(UserId, AvatarId); | ||||
/// <summary> Returns a by-name unique identifier separating this user from others with the same name. </summary> | |||||
public string Discriminator { get; internal set; } | |||||
/// <summary> Returns the datetime that this user joined this server. </summary> | |||||
public DateTime JoinedAt { get; internal set; } | public DateTime JoinedAt { get; internal set; } | ||||
public bool IsMuted { get; internal set; } | public bool IsMuted { get; internal set; } | ||||
@@ -34,12 +35,10 @@ namespace Discord | |||||
public string GameId { get; internal set; } | public string GameId { get; internal set; } | ||||
/// <summary> Returns the current status for this user. </summary> | /// <summary> Returns the current status for this user. </summary> | ||||
public string Status { get; internal set; } | public string Status { get; internal set; } | ||||
/// <summary> Returns the time this user's status was last changed in this server. </summary> | |||||
public DateTime StatusSince { get; internal set; } | |||||
/// <summary> Returns the time this user last sent/edited a message, started typing or sent voice data in this server. </summary> | /// <summary> Returns the time this user last sent/edited a message, started typing or sent voice data in this server. </summary> | ||||
public DateTime? LastActivity { get; private set; } | |||||
public DateTime? LastActivityAt { get; private set; } | |||||
/// <summary> Returns the time this user was last seen online in this server. </summary> | /// <summary> Returns the time this user was last seen online in this server. </summary> | ||||
public DateTime? LastOnline => Status != UserStatus.Offline ? DateTime.UtcNow : _lastOnline; | |||||
public DateTime? LastOnlineAt => Status != UserStatus.Offline ? DateTime.UtcNow : _lastOnline; | |||||
private DateTime _lastOnline; | private DateTime _lastOnline; | ||||
public string UserId { get; } | public string UserId { get; } | ||||
@@ -98,11 +97,9 @@ namespace Discord | |||||
{ | { | ||||
if (Status != model.Status) | if (Status != model.Status) | ||||
{ | { | ||||
var now = DateTime.UtcNow; | |||||
Status = model.Status; | Status = model.Status; | ||||
StatusSince = now; | |||||
if (Status == UserStatus.Offline) | if (Status == UserStatus.Offline) | ||||
_lastOnline = now; | |||||
_lastOnline = DateTime.UtcNow; | |||||
} | } | ||||
GameId = model.GameId; | GameId = model.GameId; | ||||
} | } | ||||
@@ -124,8 +121,8 @@ namespace Discord | |||||
internal void UpdateActivity(DateTime? activity = null) | internal void UpdateActivity(DateTime? activity = null) | ||||
{ | { | ||||
if (LastActivity == null || activity > LastActivity.Value) | |||||
LastActivity = activity ?? DateTime.UtcNow; | |||||
if (LastActivityAt == null || activity > LastActivityAt.Value) | |||||
LastActivityAt = activity ?? DateTime.UtcNow; | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -17,9 +17,15 @@ namespace Discord | |||||
/// <summary> Returns the unique identifier for this user. </summary> | /// <summary> Returns the unique identifier for this user. </summary> | ||||
public string Id { get; } | public string Id { get; } | ||||
/// <summary> Returns the name of this user. </summary> | |||||
public string Name => Memberships.Where(x => x.Name != null).Select(x => x.Name).FirstOrDefault(); | |||||
/// <summary> Returns the name of this user on this server. </summary> | |||||
public string Name { get; internal set; } | |||||
/// <summary> Returns a by-name unique identifier separating this user from others with the same name. </summary> | |||||
public string Discriminator { get; internal set; } | |||||
/// <summary> Returns the unique identifier for this user's current avatar. </summary> | |||||
public string AvatarId { get; internal set; } | |||||
/// <summary> Returns the URL to this user's current avatar. </summary> | |||||
public string AvatarUrl => Endpoints.UserAvatar(Id, AvatarId); | |||||
/// <summary> Returns the email for this user. </summary> | /// <summary> Returns the email for this user. </summary> | ||||
/// <remarks> This field is only ever populated for the current logged in user. </remarks> | /// <remarks> This field is only ever populated for the current logged in user. </remarks> | ||||
[JsonIgnore] | [JsonIgnore] | ||||
@@ -45,7 +51,7 @@ namespace Discord | |||||
public IEnumerable<Message> Messages => _client.Messages.Where(x => x.UserId == Id); | public IEnumerable<Message> Messages => _client.Messages.Where(x => x.UserId == Id); | ||||
/// <summary> Returns the id for the game this user is currently playing. </summary> | /// <summary> Returns the id for the game this user is currently playing. </summary> | ||||
public string GameId => Memberships.Where(x => x.GameId != null).Select(x => x.GameId).FirstOrDefault(); | |||||
/*public string GameId => Memberships.Where(x => x.GameId != null).Select(x => x.GameId).FirstOrDefault(); | |||||
/// <summary> Returns the current status for this user. </summary> | /// <summary> Returns the current status for this user. </summary> | ||||
public string Status => Memberships.OrderByDescending(x => x.StatusSince).Select(x => x.Status).FirstOrDefault(); | public string Status => Memberships.OrderByDescending(x => x.StatusSince).Select(x => x.Status).FirstOrDefault(); | ||||
/// <summary> Returns the time this user's status was last changed. </summary> | /// <summary> Returns the time this user's status was last changed. </summary> | ||||
@@ -63,7 +69,7 @@ namespace Discord | |||||
} | } | ||||
} | } | ||||
/// <summary> Returns the time this user was last seen online. </summary> | /// <summary> Returns the time this user was last seen online. </summary> | ||||
public DateTime? LastOnline => Memberships.OrderByDescending(x => x.LastOnline).Select(x => x.LastOnline).FirstOrDefault(); | |||||
public DateTime? LastOnline => Memberships.OrderByDescending(x => x.LastOnline).Select(x => x.LastOnline).FirstOrDefault();*/ | |||||
internal User(DiscordClient client, string id) | internal User(DiscordClient client, string id) | ||||
{ | { | ||||
@@ -72,8 +78,18 @@ namespace Discord | |||||
_servers = new ConcurrentDictionary<string, bool>(); | _servers = new ConcurrentDictionary<string, bool>(); | ||||
} | } | ||||
internal void Update(UserReference model) | |||||
{ | |||||
if (model.Avatar != null) | |||||
AvatarId = model.Avatar; | |||||
if (model.Discriminator != null) | |||||
Discriminator = model.Discriminator; | |||||
if (model.Username != null) | |||||
Name = model.Username; | |||||
} | |||||
internal void Update(SelfUserInfo model) | internal void Update(SelfUserInfo model) | ||||
{ | { | ||||
Update(model as UserReference); | |||||
Email = model.Email; | Email = model.Email; | ||||
IsVerified = model.IsVerified; | IsVerified = model.IsVerified; | ||||
} | } | ||||