Hid old CurrentUser, exposed GlobalUser via CurrentUser

This commit is contained in:
RogueException
2015-11-08 10:38:31 -04:00
parent 674e6674b7
commit 9487fba23f
5 changed files with 16 additions and 14 deletions

View File

@@ -108,9 +108,12 @@ namespace Discord
RaiseEvent(nameof(ProfileUpdated), () => ProfileUpdated(this, EventArgs.Empty));
}
/// <summary> Returns the current logged-in user. </summary>
public User CurrentUser => _currentUser;
private User _currentUser;
/// <summary> Returns the current logged-in user in a private channel. </summary>
internal User PrivateUser => _privateUser;
private User _privateUser;
/// <summary> Returns information about the currently logged-in account. </summary>
public GlobalUser CurrentUser => _privateUser.GlobalUser;
/// <summary> Returns a collection of all users this client can currently see. </summary>
internal GlobalUsers GlobalUsers => _globalUsers;
@@ -244,7 +247,7 @@ namespace Discord
CheckReady();
return _api.EditUser(currentPassword: currentPassword,
username: username ?? _currentUser?.Name, email: email ?? _currentUser?.GlobalUser.Email, password: password,
username: username ?? _privateUser?.Name, email: email ?? _privateUser?.GlobalUser.Email, password: password,
avatarType: avatarType, avatar: avatar);
}

View File

@@ -270,7 +270,7 @@ namespace Discord
_servers.Clear();
_globalUsers.Clear();
_currentUser = null;
_privateUser = null;
}
public T AddService<T>(T obj)
@@ -309,9 +309,9 @@ namespace Discord
{
base.OnReceivedEvent(e).Wait(); //This cannot be an await, or we'll get later messages before we're ready
var data = e.Payload.ToObject<ReadyEvent>(_serializer);
_currentUser = _users.GetOrAdd(data.User.Id, null);
_currentUser.Update(data.User);
_currentUser.GlobalUser.Update(data.User);
_privateUser = _users.GetOrAdd(data.User.Id, null);
_privateUser.Update(data.User);
_privateUser.GlobalUser.Update(data.User);
foreach (var model in data.Guilds)
{
if (!model.Unavailable)

View File

@@ -168,7 +168,7 @@ namespace Discord
{
_members = new Dictionary<string, User>()
{
{ _client.CurrentUserId, _client.CurrentUser },
{ _client.CurrentUserId, _client.PrivateUser },
{ _recipient.Id, _recipient.Value }
};
}

View File

@@ -3,11 +3,10 @@ using Newtonsoft.Json;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
namespace Discord
{
internal sealed class GlobalUser : CachedObject
public sealed class GlobalUser : CachedObject
{
private readonly ConcurrentDictionary<string, User> _users;
@@ -22,7 +21,7 @@ namespace Discord
/// <summary> Returns the private messaging channel with this user, if one exists. </summary>
[JsonIgnore]
public Channel PrivateChannel
internal Channel PrivateChannel
{
get { return _privateChannel; }
internal set
@@ -36,7 +35,7 @@ namespace Discord
/// <summary> Returns a collection of all server-specific data for every server this user is a member of. </summary>
[JsonIgnore]
public IEnumerable<User> Memberships => _users.Select(x => _client.Users[Id, x.Key]);
internal IEnumerable<User> Memberships => _users.Select(x => _client.Users[Id, x.Key]);
internal GlobalUser(DiscordClient client, string id)
: base(client, id)

View File

@@ -244,7 +244,7 @@ namespace Discord
}
else
{
var me = _client.CurrentUser;
var me = _client.PrivateUser;
IsMentioningMe = MentionedUsers?.Contains(me) ?? false;
}
}