| @@ -108,9 +108,12 @@ namespace Discord | |||||
| RaiseEvent(nameof(ProfileUpdated), () => ProfileUpdated(this, EventArgs.Empty)); | 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> | /// <summary> Returns a collection of all users this client can currently see. </summary> | ||||
| internal GlobalUsers GlobalUsers => _globalUsers; | internal GlobalUsers GlobalUsers => _globalUsers; | ||||
| @@ -244,7 +247,7 @@ namespace Discord | |||||
| CheckReady(); | CheckReady(); | ||||
| return _api.EditUser(currentPassword: currentPassword, | 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); | avatarType: avatarType, avatar: avatar); | ||||
| } | } | ||||
| @@ -270,7 +270,7 @@ namespace Discord | |||||
| _servers.Clear(); | _servers.Clear(); | ||||
| _globalUsers.Clear(); | _globalUsers.Clear(); | ||||
| _currentUser = null; | |||||
| _privateUser = null; | |||||
| } | } | ||||
| public T AddService<T>(T obj) | 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 | 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); | 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) | foreach (var model in data.Guilds) | ||||
| { | { | ||||
| if (!model.Unavailable) | if (!model.Unavailable) | ||||
| @@ -168,7 +168,7 @@ namespace Discord | |||||
| { | { | ||||
| _members = new Dictionary<string, User>() | _members = new Dictionary<string, User>() | ||||
| { | { | ||||
| { _client.CurrentUserId, _client.CurrentUser }, | |||||
| { _client.CurrentUserId, _client.PrivateUser }, | |||||
| { _recipient.Id, _recipient.Value } | { _recipient.Id, _recipient.Value } | ||||
| }; | }; | ||||
| } | } | ||||
| @@ -3,11 +3,10 @@ using Newtonsoft.Json; | |||||
| using System.Collections.Concurrent; | using System.Collections.Concurrent; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Linq; | using System.Linq; | ||||
| using System.Threading; | |||||
| namespace Discord | namespace Discord | ||||
| { | { | ||||
| internal sealed class GlobalUser : CachedObject | |||||
| public sealed class GlobalUser : CachedObject | |||||
| { | { | ||||
| private readonly ConcurrentDictionary<string, User> _users; | 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> | /// <summary> Returns the private messaging channel with this user, if one exists. </summary> | ||||
| [JsonIgnore] | [JsonIgnore] | ||||
| public Channel PrivateChannel | |||||
| internal Channel PrivateChannel | |||||
| { | { | ||||
| get { return _privateChannel; } | get { return _privateChannel; } | ||||
| internal set | 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> | /// <summary> Returns a collection of all server-specific data for every server this user is a member of. </summary> | ||||
| [JsonIgnore] | [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) | internal GlobalUser(DiscordClient client, string id) | ||||
| : base(client, id) | : base(client, id) | ||||
| @@ -244,7 +244,7 @@ namespace Discord | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| var me = _client.CurrentUser; | |||||
| var me = _client.PrivateUser; | |||||
| IsMentioningMe = MentionedUsers?.Contains(me) ?? false; | IsMentioningMe = MentionedUsers?.Contains(me) ?? false; | ||||
| } | } | ||||
| } | } | ||||