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