Browse Source

Undid a few changes to User

tags/docs-0.9
Brandon Smith 9 years ago
parent
commit
c7e6a37b4b
4 changed files with 33 additions and 16 deletions
  1. +2
    -0
      src/Discord.Net/DiscordClient.API.cs
  2. +2
    -0
      src/Discord.Net/DiscordClient.cs
  3. +8
    -11
      src/Discord.Net/Models/Member.cs
  4. +21
    -5
      src/Discord.Net/Models/User.cs

+ 2
- 0
src/Discord.Net/DiscordClient.API.cs View File

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


+ 2
- 0
src/Discord.Net/DiscordClient.cs View File

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


+ 8
- 11
src/Discord.Net/Models/Member.cs View File

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

+ 21
- 5
src/Discord.Net/Models/User.cs View File

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


Loading…
Cancel
Save